Updated

app/models/concerns / geoip_lookup.rb

A
51 lines of codes
8 methods
3.6 complexity/method
1 churn
28.96 complexity
0 duplications
module GeoipLookup
  1. GeoipLookup has no descriptive comment
extend ActiveSupport::Concern module ClassMethods
  1. GeoipLookup::ClassMethods has no descriptive comment
def geoip_lookup(ip) geoip_db.lookup(ip) rescue Errno::ENOENT => e
  1. 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
  1. 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
  1. GeoipLookup::ClassMethods#country_name_for refers to 'result' more than self (maybe move it to another class?)
end end private def geoip_db
  1. 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