module GeoipLookup - GeoipLookup has no descriptive comment
extend ActiveSupport::Concern
module ClassMethods - GeoipLookup::ClassMethods has no descriptive comment
def geoip_lookup(ip)
geoip_db.lookup(ip)
rescue Errno::ENOENT => e - GeoipLookup::ClassMethods#geoip_lookup has the variable name 'e'
nil
end
def iso_code_for(ip)
if result = geoip_lookup(ip)
result.found? ? result.country.iso_code : nil - GeoipLookup::ClassMethods#iso_code_for refers to 'result' more than self (maybe move it to another class?)
end
end
def country_name_for(ip)
if result = geoip_lookup(ip)
result.found? ? result.country.name : nil - GeoipLookup::ClassMethods#country_name_for refers to 'result' more than self (maybe move it to another class?)
end
end
private
def geoip_db - GeoipLookup::ClassMethods#geoip_db doesn't depend on instance state (maybe move it to another class?)
Thread.current[:__geoip_db__] ||= MaxMindDB.new(ENV.fetch('GEOIP_DB_PATH'))
end
end
def geoip_lookup(ip)
self.class.geoip_lookup(ip)
end
def iso_code_for(ip)
self.class.iso_code_for(ip)
end
def country_name_for(ip)
self.class.country_name_for(ip)
end
def ip_location
return unless ip_address?
if iso_code = iso_code_for(ip_address)
"#{ip_address} (#{iso_code})"
else
ip_address
end
end
end