From e9896f191db21507f714ea8c1bc643c4e65f9679 Mon Sep 17 00:00:00 2001 From: gxbe <triumph@hushmail.com> Date: Mon, 27 Jan 2014 12:12:58 -0500 Subject: [PATCH] added support for JRuby via jgeo-ip gem --- lib/geocoder/lookups/maxmind_local.rb | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/geocoder/lookups/maxmind_local.rb b/lib/geocoder/lookups/maxmind_local.rb index 1045b748..09aad227 100644 --- a/lib/geocoder/lookups/maxmind_local.rb +++ b/lib/geocoder/lookups/maxmind_local.rb @@ -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 -- GitLab