Sha256: c8fd4bcaaafeebd9f610ad1b90ff9c06cc19b69b5c54cd4282554e6eb14526ec

Contents?: true

Size: 924 Bytes

Versions: 2

Compression:

Stored size: 924 Bytes

Contents

#This didn't belong on ExceptionNotifier and made backtraces worse.  To keep original functionality in place
#'ActionController::Base.send :include, ExceptionNotification::ConsiderLocal' or just include in your controller
module ExceptionNotification::ConsiderLocal
  module ClassMethods
    def self.included(target)
      require 'ipaddr'
      target.extend(ClassMethods)
    end
    
    def consider_local(*args)
      local_addresses.concat(args.flatten.map { |a| IPAddr.new(a) })
    end

    def local_addresses
      addresses = read_inheritable_attribute(:local_addresses)
      unless addresses
        addresses = [IPAddr.new("127.0.0.1")]
        write_inheritable_attribute(:local_addresses, addresses)
      end
      addresses
    end
  end
  
private
  
  def local_request?
    remote = IPAddr.new(request.remote_ip)
    !self.class.local_addresses.detect { |addr| addr.include?(remote) }.nil?
  end
  
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
panmind-exception_notification-2.3.10 lib/exception_notification/consider_local.rb
exception_notification-2.3.3.0 lib/exception_notification/consider_local.rb