Skip to content
Snippets Groups Projects
Commit 0674c072 authored by Anderson Bravalheri's avatar Anderson Bravalheri
Browse files

Reimplemented +set_defaults+, all tests are well succeded

parent 7276de0b
No related branches found
No related tags found
No related merge requests found
require 'singleton'
module Geocoder
# This class handle the configuration process of Geocoder gem, and can be used
# to change some functional aspects, like, the geocoding service provider, or
# the units of calculations.
#
# == Geocoder Configuration
#
# The configuration of Geocoder can be done in to ways:
# - using +Geocoder#configure+ method:
#
# Geocoder.configure do |config|
# config.timeout = 3 # geocoding service timeout (secs)
# config.lookup = :google # name of geocoding service (symbol)
# config.language = :en # ISO-639 language code
# config.use_https = false # use HTTPS for lookup requests? (if supported)
# config.http_proxy = nil # HTTP proxy server (user:pass@host:port)
# config.https_proxy = nil # HTTPS proxy server (user:pass@host:port)
# config.api_key = nil # API key for geocoding service
# config.cache = nil # cache object (must respond to #[], #[]=, and #keys)
# config.cache_prefix = "geocoder:" # prefix (string) to use for all cache keys
#
# # exceptions that should not be rescued by default
# # (if you want to implement custom error handling);
# # supports SocketError and TimeoutError
# config.always_raise = []
#
# # Calculation options
# @units = :km # :km for kilometers or :mi for miles
# @method = :spherical # :spherical or :linear
# end
#
# - or using +Geocoder::Configuration+ class directly, like in:
#
# Geocoder::Configuration.language = 'pt-BR'
#
# == Notes
#
# All configurations are optional, the default values were shown in the first
# example (with +Geocoder#configure+).
class Configuration
include Singleton
......@@ -11,7 +51,12 @@ module Geocoder
attr_accessor *CONFIGURABLE
def initialize
def initialize # :nodoc
set_defaults
end
# This method will set the configuration options to the default values
def set_defaults
@timeout = 3 # geocoding service timeout (secs)
@lookup = :google # name of geocoding service (symbol)
@language = :en # ISO-639 language code
......@@ -21,6 +66,7 @@ module Geocoder
@api_key = nil # API key for geocoding service
@cache = nil # cache object (must respond to #[], #[]=, and #keys)
@cache_prefix = "geocoder:" # prefix (string) to use for all cache keys
# exceptions that should not be rescued by default
# (if you want to implement custom error handling);
# supports SocketError and TimeoutError
......@@ -31,7 +77,8 @@ module Geocoder
@method = :spherical # More precise
end
# delegates getters and setters for all configuration settings to the instance
# Delegates getters and setters for all configuration settings,
# and +set_defaults+ to the singleton instance.
instance_eval(CONFIGURABLE.map do |method|
meth = method.to_s
<<-EOS
......@@ -44,6 +91,13 @@ module Geocoder
end
EOS
end.join("\n\n"))
class << self
# This method will set the configuration options to the default values
def set_defaults
instance.set_defaults
end
end
end
end
......@@ -33,3 +33,4 @@ class CustomBlockTest < Test::Unit::TestCase
assert_nil e.address
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