Skip to content
Snippets Groups Projects
Commit e9896f19 authored by gxbe's avatar gxbe
Browse files

added support for JRuby via jgeo-ip gem

parent 3c7e606f
No related branches found
No related tags found
No related merge requests found
......@@ -5,12 +5,19 @@ module Geocoder::Lookup
class MaxmindLocal < Base
def initialize
begin
require 'geoip'
rescue LoadError => e
raise 'Could not load geoip dependency. To use MaxMind Local lookup you must add geoip gem to your Gemfile or have it installed in your system.'
if RUBY_PLATFORM == "java"
begin
require 'jgeoip'
rescue LoadError => e
raise 'Could not load geoip dependency. To use MaxMind Local lookup you must add geoip gem to your Gemfile or have it installed in your system.'
end
else
begin
require 'geoip'
rescue LoadError => e
raise 'Could not load geoip dependency. To use MaxMind Local lookup you must add geoip gem to your Gemfile or have it installed in your system.'
end
end
super
end
......@@ -32,8 +39,11 @@ module Geocoder::Lookup
"Geocoder.configure(:maxmind_local => {:database => ...}), "
)
end
result = GeoIP.new(configuration[:database]).city(query.to_s)
if RUBY_PLATFORM == "java"
result = JGeoIP.new(configuration[:database]).city(query.to_s)
else
result = GeoIP.new(configuration[:database]).city(query.to_s)
end
result.nil? ? [] : [result.to_hash]
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment