From 5699eeb5d751b94e2a86d375d5867cedae365d94 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 24 Feb 2014 11:27:02 -0500 Subject: [PATCH] Reduce code duplication. --- lib/geocoder/lookups/maxmind_local.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/geocoder/lookups/maxmind_local.rb b/lib/geocoder/lookups/maxmind_local.rb index 465c3614..cd059902 100644 --- a/lib/geocoder/lookups/maxmind_local.rb +++ b/lib/geocoder/lookups/maxmind_local.rb @@ -6,9 +6,10 @@ module Geocoder::Lookup def initialize begin - require (RUBY_PLATFORM == 'java' ? 'jgeoip' : 'geoip') + gem = RUBY_PLATFORM == 'java' ? 'jgeoip' : 'geoip' + require gem 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 super end @@ -31,8 +32,9 @@ module Geocoder::Lookup "Geocoder.configure(:maxmind_local => {:database => ...}), " ) 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] end end -end \ No newline at end of file +end -- GitLab