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

reduced duplication

parent 176464d8
No related branches found
No related tags found
No related merge requests found
...@@ -5,18 +5,10 @@ module Geocoder::Lookup ...@@ -5,18 +5,10 @@ module Geocoder::Lookup
class MaxmindLocal < Base class MaxmindLocal < Base
def initialize def initialize
if RUBY_PLATFORM == "java" begin
begin require (RUBY_PLATFORM == java ? 'jgeoip' : 'geoip')
require 'jgeoip' 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 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
...@@ -39,12 +31,7 @@ module Geocoder::Lookup ...@@ -39,12 +31,7 @@ module Geocoder::Lookup
"Geocoder.configure(:maxmind_local => {:database => ...}), " "Geocoder.configure(:maxmind_local => {:database => ...}), "
) )
end end
if RUBY_PLATFORM == "java" result = (RUBY_PLATFORM == "java" ? JGeoIP.new(configuration[:database]).city(query.to_s) : 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
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