Sha256: 3a50fe1a9a9650945a9a79ffb3e4443c550f844e870331200fe65f08b658de61

Contents?: true

Size: 1.22 KB

Versions: 13

Compression:

Stored size: 1.22 KB

Contents

module NginxTail
  module LocalIpAddresses
    
    #
    # local IP addresses, for filtering and formatting purposes
    #
    # e.g. downstream proxy servers (nginx web servers -> passenger app servers)
    #

    def self.included(base) # :nodoc:
      base.class_eval do

        @@local_ip_addresses = []
        
        # mainly (solely?) for testing purposes...
        def self.local_ip_addresses()
          @@local_ip_addresses.dup
        end
        
        # mainly (solely?) for testing purposes...
        def self.reset_local_ip_addresses()
          while !@@local_ip_addresses.empty? ; @@local_ip_addresses.pop ; end
        end
        
        def self.add_local_ip_address(local_ip_address)
          (@@local_ip_addresses << local_ip_address).uniq!
        end

        def self.local_ip_address?(remote_addr)
          @@local_ip_addresses.include?(remote_addr)
        end

        # this ensures the below module methods actually make sense...
        raise "Class #{base.name} should implement instance method 'remote_addr'" unless base.instance_methods.map(&:to_s).include? 'remote_addr'
        
      end
    end
    
    def local_ip_address?
      self.class.local_ip_address?(self.remote_addr)
    end
    
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ntail-1.3.1 lib/ntail/local_ip_addresses.rb
ntail-1.3.0 lib/ntail/local_ip_addresses.rb
ntail-1.2.0 lib/ntail/local_ip_addresses.rb
ntail-1.1.4 lib/ntail/local_ip_addresses.rb
ntail-1.1.3 lib/ntail/local_ip_addresses.rb
ntail-1.1.2 lib/ntail/local_ip_addresses.rb
ntail-1.1.1 lib/ntail/local_ip_addresses.rb
ntail-1.1.0 lib/ntail/local_ip_addresses.rb
ntail-1.0.2 lib/ntail/local_ip_addresses.rb
ntail-1.0.0 lib/ntail/local_ip_addresses.rb
ntail-0.2.0 lib/ntail/local_ip_addresses.rb
ntail-0.1.0 lib/ntail/local_ip_addresses.rb
ntail-0.0.12 lib/ntail/local_ip_addresses.rb