diff --git a/lib/geocoder.rb b/lib/geocoder.rb index c7fb016d947b99ad2e4dd4d1d769fb6bd3647933..778c12b9246aac0ce4e2891ef7ba8718e6d64024 100644 --- a/lib/geocoder.rb +++ b/lib/geocoder.rb @@ -91,12 +91,8 @@ module Geocoder # Retrieve a Lookup object from the store. # def get_lookup(name) - unless defined?(@lookups) - @lookups = {} - end - unless @lookups.include?(name) - @lookups[name] = spawn_lookup(name) - end + @lookups = {} unless defined?(@lookups) + @lookups[name] = spawn_lookup(name) unless @lookups.include?(name) @lookups[name] end @@ -108,9 +104,9 @@ module Geocoder name = name.to_s require "geocoder/lookups/#{name}" klass = name.split("_").map{ |i| i[0...1].upcase + i[1..-1] }.join - eval("Geocoder::Lookup::#{klass}.new") + Geocoder::Lookup.const_get(klass).new else - valids = valid_lookups.map{ |l| ":#{l}" }.join(", ") + valids = valid_lookups.join(", ") raise ConfigurationError, "Please specify a valid lookup for Geocoder " + "(#{name.inspect} is not one of: #{valids})." end diff --git a/lib/geocoder/configuration.rb b/lib/geocoder/configuration.rb index 54fceacf4493fe1b802df34ee4005f1e6b071a37..b565699235ade3999e9ce54417fa0944ff8c81aa 100644 --- a/lib/geocoder/configuration.rb +++ b/lib/geocoder/configuration.rb @@ -39,20 +39,21 @@ module Geocoder end # define getters and setters for all configuration settings - self.options_and_defaults.each do |o,d| - eval("def self.#{o}; @@#{o}; end") - eval("def self.#{o}=(obj); @@#{o} = obj; end") + self.options_and_defaults.each do |option, default| + class_eval(<<-END, __FILE__, __LINE__ + 1) + + @@#{option} = default unless defined? @@#{option} + + def self.#{option} + @@#{option} + end + + def self.#{option}=(obj) + @@#{option} = obj + end + + END end - ## - # Set all values to default. - # - def self.set_defaults - self.options_and_defaults.each do |o,d| - self.send("#{o}=", d) - end - end end end - -Geocoder::Configuration.set_defaults diff --git a/lib/geocoder/lookups/base.rb b/lib/geocoder/lookups/base.rb index 39490e81d92e684961801fd1d7fc32170b1f929b..8a443fee520c281735b18d2e3f2c34e2a4904d3e 100644 --- a/lib/geocoder/lookups/base.rb +++ b/lib/geocoder/lookups/base.rb @@ -87,7 +87,7 @@ module Geocoder # Class of the result objects # def result_class - eval("Geocoder::Result::#{self.class.to_s.split(":").last}") + Geocoder::Result.const_get(self.class.to_s.split(":").last) end ## diff --git a/lib/geocoder/models/base.rb b/lib/geocoder/models/base.rb index 1e944264aced08e5633551a088ae8329cb6a7b38..836233162770542dc063784b4d448c8324792708 100644 --- a/lib/geocoder/models/base.rb +++ b/lib/geocoder/models/base.rb @@ -31,7 +31,7 @@ module Geocoder unless @geocoder_options @geocoder_options = {} require "geocoder/stores/#{geocoder_file_name}" - include eval("Geocoder::Store::" + geocoder_module_name) + include Geocoder::Store.const_get(geocoder_module_name) end @geocoder_options.merge! options end diff --git a/lib/geocoder/models/mongo_base.rb b/lib/geocoder/models/mongo_base.rb index 393e007fbd27793960224a222801838e674c1ab4..15bbbabe848b51c99247c2339dae34b764f45b1a 100644 --- a/lib/geocoder/models/mongo_base.rb +++ b/lib/geocoder/models/mongo_base.rb @@ -38,14 +38,14 @@ module Geocoder unless geocoder_initialized? @geocoder_options = {} require "geocoder/stores/#{geocoder_file_name}" - include eval("Geocoder::Store::" + geocoder_module_name) + include Geocoder::Store.const_get(geocoder_module_name) end @geocoder_options.merge! options end def geocoder_initialized? begin - included_modules.include? eval("Geocoder::Store::" + geocoder_module_name) + included_modules.include? Geocoder::Store.const_get(geocoder_module_name) rescue NameError false end diff --git a/test/configuration_test.rb b/test/configuration_test.rb index 61593c6b5730f832ef8f24384fd365021fe46f92..cece36b74bdcc566fca9094c7e0dcd377238ce7f 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -9,4 +9,5 @@ class ConfigurationTest < Test::Unit::TestCase Geocoder.search "something dumb" end end + end diff --git a/test/custom_block_test.rb b/test/custom_block_test.rb index ab2ad9e005b80896370271a2553cac770c263d64..8fab62e819aa6ff05a1b706e185ab7aba92008fc 100644 --- a/test/custom_block_test.rb +++ b/test/custom_block_test.rb @@ -3,10 +3,6 @@ require 'test_helper' class CustomBlockTest < Test::Unit::TestCase - def setup - Geocoder::Configuration.set_defaults - end - def test_geocode_with_block_runs_block e = Event.new(*venue_params(:msg)) coords = [40.750354, -73.993371] diff --git a/test/error_handling_test.rb b/test/error_handling_test.rb index f9d1f41a7393e7b5c094243f5c0a0994542a5659..42b3c3fd1fd98711d97f133c71b5aa79fcb52e23 100644 --- a/test/error_handling_test.rb +++ b/test/error_handling_test.rb @@ -3,10 +3,6 @@ require 'test_helper' class ErrorHandlingTest < Test::Unit::TestCase - def setup - Geocoder::Configuration.set_defaults - end - def test_does_not_choke_on_timeout # keep test output clean: suppress timeout warning orig = $VERBOSE; $VERBOSE = nil diff --git a/test/geocoder_test.rb b/test/geocoder_test.rb index 2a0b02461f9e71268e47cc03814a7417ac1c7ae0..fe1682004ef4c537d7d6882e320c3c4b40d680a5 100644 --- a/test/geocoder_test.rb +++ b/test/geocoder_test.rb @@ -3,10 +3,6 @@ require 'test_helper' class GeocoderTest < Test::Unit::TestCase - def setup - Geocoder::Configuration.set_defaults - end - def test_distance_to_returns_float v = Venue.new(*venue_params(:msg)) v.latitude, v.longitude = [40.750354, -73.993371] diff --git a/test/https_test.rb b/test/https_test.rb index acba01e68a5f6428581c7b2bc650b5a5d3807273..58219d33cc8f013746583b0d20a699e93b534ad8 100644 --- a/test/https_test.rb +++ b/test/https_test.rb @@ -3,10 +3,6 @@ require 'test_helper' class HttpsTest < Test::Unit::TestCase - def setup - Geocoder::Configuration.set_defaults - end - def test_uses_https_for_secure_query Geocoder::Configuration.use_https = true g = Geocoder::Lookup::Google.new diff --git a/test/method_aliases_test.rb b/test/method_aliases_test.rb index f44c3478487de0617ad043485d4cb20918218bd9..993e96769bb3a1bbf307f6abe9e25208fb115673 100644 --- a/test/method_aliases_test.rb +++ b/test/method_aliases_test.rb @@ -3,10 +3,6 @@ require 'test_helper' class MethodAliasesTest < Test::Unit::TestCase - def setup - Geocoder::Configuration.set_defaults - end - def test_distance_from_is_alias_for_distance_to v = Venue.new(*venue_params(:msg)) v.latitude, v.longitude = [40.750354, -73.993371] diff --git a/test/mongoid_test.rb b/test/mongoid_test.rb index c4fb8ae07251f61f3c52480838b308c5ed9e3e36..44b4ca9a0798538974177cfb79332657d9908e3b 100644 --- a/test/mongoid_test.rb +++ b/test/mongoid_test.rb @@ -7,10 +7,6 @@ require 'mongoid_test_helper' class MongoidTest < Test::Unit::TestCase - def setup - Geocoder::Configuration.set_defaults - end - def test_geocoded_check p = Place.new(*venue_params(:msg)) p.location = [40.750354, -73.993371] diff --git a/test/proxy_test.rb b/test/proxy_test.rb index fe4236050ff6c986e3c3e0ea49fde232bc569880..d701fdce39d2663d5732379676d6960e2268c796 100644 --- a/test/proxy_test.rb +++ b/test/proxy_test.rb @@ -3,10 +3,6 @@ require 'test_helper' class ProxyTest < Test::Unit::TestCase - def setup - Geocoder::Configuration.set_defaults - end - def test_uses_proxy_when_specified Geocoder::Configuration.http_proxy = 'localhost' lookup = Geocoder::Lookup::Google.new diff --git a/test/services_test.rb b/test/services_test.rb index da81f7c9b9965408ccef30de2f9ce3cd799eca05..ab73a8e7e1295066cb3f6188d18a8dedf39e32e9 100644 --- a/test/services_test.rb +++ b/test/services_test.rb @@ -3,10 +3,6 @@ require 'test_helper' class ServicesTest < Test::Unit::TestCase - def setup - Geocoder::Configuration.set_defaults - end - # --- Google --- diff --git a/test/test_helper.rb b/test/test_helper.rb index 589ebcbe548b3348ef0ab09d75cc236bfad68f46..380c7f302500081306fd8e91314320edf4205c6e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -231,6 +231,12 @@ end class Test::Unit::TestCase + + def teardown + Geocoder.send(:remove_const, :Configuration) + load "geocoder/configuration.rb" + end + def venue_params(abbrev) { :msg => ["Madison Square Garden", "4 Penn Plaza, New York, NY"]