Skip to content
Snippets Groups Projects
Commit 5699eeb5 authored by Alex Reisner's avatar Alex Reisner
Browse files

Reduce code duplication.

parent 95640973
No related branches found
No related tags found
No related merge requests found
...@@ -6,9 +6,10 @@ module Geocoder::Lookup ...@@ -6,9 +6,10 @@ module Geocoder::Lookup
def initialize def initialize
begin begin
require (RUBY_PLATFORM == 'java' ? 'jgeoip' : 'geoip') gem = RUBY_PLATFORM == 'java' ? 'jgeoip' : 'geoip'
require gem
rescue LoadError => e 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.' raise 'Could not load geoip dependency. To use MaxMind Local lookup you must add the #{gem} gem to your Gemfile or have it installed in your system.'
end end
super super
end end
...@@ -31,7 +32,8 @@ module Geocoder::Lookup ...@@ -31,7 +32,8 @@ module Geocoder::Lookup
"Geocoder.configure(:maxmind_local => {:database => ...}), " "Geocoder.configure(:maxmind_local => {:database => ...}), "
) )
end end
result = (RUBY_PLATFORM == "java" ? JGeoIP.new(configuration[:database]).city(query.to_s) : GeoIP.new(configuration[:database]).city(query.to_s)) geoip_class = RUBY_PLATFORM == "java" ? JGeoIP : GeoIP
result = geoip_class.new(configuration[:database]).city(query.to_s)
result.nil? ? [] : [result.to_hash] result.nil? ? [] : [result.to_hash]
end end
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment