module ApacheLogGeo
Constants
- COUNTRY_CODES
Public Instance Methods
db_adapter_load()
click to toggle source
# File lib.rb, line 300 def db_adapter_load adapters = { "geoip2" => { klass: Geoip2_c, gem: ['geoip2_c', '~> 0.3.3'] # can't specify it in .gemspec! }, "maxmind/db" => { klass: Maxmind}, } adapter = adapters.keys.detect do |k| begin gem(*adapters[k][:gem]) if adapters[k][:gem] require k rescue LoadError next nil end k end adapters[adapter][:klass] end
errx(exit_code, msg)
click to toggle source
# File lib.rb, line 16 def errx exit_code, msg $stderr.puts "#{File.basename $0} error: #{msg}" exit exit_code end
geo_db_location()
click to toggle source
save user some typing if we can guess the OS
# File lib.rb, line 4 def geo_db_location datadir = case RUBY_PLATFORM when /linux/ then '/usr/share' when /cygwin|msys/ then '/usr/share' when /darwin/ then '/usr/local/var' # untested when /freebsd/ then '/usr/local/share' else nil end return 'GeoLite2-City.mmdb' unless datadir File.join datadir, 'GeoIP/GeoLite2-City.mmdb' end
sigint_handler()
click to toggle source
# File lib.rb, line 22 def sigint_handler; proc {|s| puts ""; exit 128+s }; end
warnx(msg;)
click to toggle source
# File lib.rb, line 21 def warnx msg; $stderr.puts "#{File.basename $0} warning: #{msg}"; end