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

Add Geocoder.config for direct access to hash.

parent 3e1ee32c
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,20 @@ module Geocoder
end
end
##
# Direct read access to the singleton's config data.
#
def self.config
Configuration.instance.data
end
##
# Direct write access to the singleton's config data.
#
def self.config=(value)
Configuration.instance.data = value
end
##
# This class handles geocoder Geocoder configuration
# (geocoding service provider, caching, units of measurement, etc).
......@@ -54,7 +68,7 @@ module Geocoder
:distances
]
attr_reader :data
attr_accessor :data
OPTIONS.each do |o|
define_method o do
......@@ -72,6 +86,7 @@ module Geocoder
def set_defaults
@data = {
# geocoding options
:timeout => 3, # geocoding service timeout (secs)
:lookup => :google, # name of street address geocoding service (symbol)
:ip_lookup => :freegeoip, # name of IP address geocoding service (symbol)
......
......@@ -151,7 +151,7 @@ module Geocoder
raise_error(err) or warn "Geocoding API connection cannot be established."
rescue TimeoutError => err
raise_error(err) or warn "Geocoding API not responding fast enough " +
"(see Geocoder::Configuration.timeout to set limit)."
"(use Geocoder.config[:timeout] to set limit)."
end
##
......
......@@ -16,11 +16,13 @@ class ConfigurationTest < Test::Unit::TestCase
def test_setting_with_class_method
Geocoder::Configuration.units = :test
assert_equal :test, Geocoder.configure.units
assert_equal :test, Geocoder.config[:units]
end
def test_setting_with_configure_method
Geocoder.configure.units = :test
assert_equal :test, Geocoder::Configuration.units
assert_equal :test, Geocoder.config[:units]
end
def test_setting_with_block_syntax
......@@ -29,6 +31,7 @@ class ConfigurationTest < Test::Unit::TestCase
end
assert_equal :test, Geocoder::Configuration.units
assert_equal :test, Geocoder.configure.units
assert_equal :test, Geocoder.config[:units]
end
def test_model_configuration
......
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