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 ...@@ -5,12 +5,19 @@ module Geocoder::Lookup
class MaxmindLocal < Base class MaxmindLocal < Base
def initialize def initialize
begin if RUBY_PLATFORM == "java"
require 'geoip' begin
rescue LoadError => e require 'jgeoip'
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.' 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 end
super super
end end
...@@ -32,8 +39,11 @@ module Geocoder::Lookup ...@@ -32,8 +39,11 @@ module Geocoder::Lookup
"Geocoder.configure(:maxmind_local => {:database => ...}), " "Geocoder.configure(:maxmind_local => {:database => ...}), "
) )
end end
if RUBY_PLATFORM == "java"
result = GeoIP.new(configuration[:database]).city(query.to_s) 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] result.nil? ? [] : [result.to_hash]
end 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