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

Improviments in configuration DSL (no argument for block configuration needed).

parent 713b6c91
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,17 @@ require "geocoder/models/mongo_mapper" ...@@ -9,6 +9,17 @@ require "geocoder/models/mongo_mapper"
module Geocoder module Geocoder
extend self extend self
# This method can be used to change some functional aspects, like,
# the geocoding service provider, or the units of calculations.
# Please see {include:Configuration}
def configure(&block)
if block_given?
module_eval(&block)
else
Configuration.instance
end
end
## ##
# Search for information about an address or a set of coordinates. # Search for information about an address or a set of coordinates.
# #
...@@ -74,6 +85,10 @@ module Geocoder ...@@ -74,6 +85,10 @@ module Geocoder
private # ----------------------------------------------------------------- private # -----------------------------------------------------------------
def config # :nodoc
Configuration.instance
end
## ##
# Get a Lookup object (which communicates with the remote geocoding API). # Get a Lookup object (which communicates with the remote geocoding API).
# Takes a search query and returns an IP or street address Lookup # Takes a search query and returns an IP or street address Lookup
...@@ -139,3 +154,4 @@ if defined?(Rails) ...@@ -139,3 +154,4 @@ if defined?(Rails)
require "geocoder/railtie" require "geocoder/railtie"
Geocoder::Railtie.insert Geocoder::Railtie.insert
end end
...@@ -9,9 +9,9 @@ module Geocoder ...@@ -9,9 +9,9 @@ module Geocoder
# == Geocoder Configuration # == Geocoder Configuration
# #
# The configuration of Geocoder can be done in to ways: # The configuration of Geocoder can be done in to ways:
# - using +Geocoder#configure+ method: # @example Using +Geocoder#configure+ method:
# #
# Geocoder.configure do |config| # Geocoder.configure do
# config.timeout = 3 # geocoding service timeout (secs) # config.timeout = 3 # geocoding service timeout (secs)
# config.lookup = :google # name of geocoding service (symbol) # config.lookup = :google # name of geocoding service (symbol)
# config.language = :en # ISO-639 language code # config.language = :en # ISO-639 language code
...@@ -32,7 +32,7 @@ module Geocoder ...@@ -32,7 +32,7 @@ module Geocoder
# @method = :spherical # :spherical or :linear # @method = :spherical # :spherical or :linear
# end # end
# #
# - or using +Geocoder::Configuration+ class directly, like in: # @example Using +Geocoder::Configuration+ class directly, like in:
# #
# Geocoder::Configuration.language = 'pt-BR' # Geocoder::Configuration.language = 'pt-BR'
# #
......
...@@ -33,7 +33,7 @@ class ConfigurationTest < Test::Unit::TestCase ...@@ -33,7 +33,7 @@ class ConfigurationTest < Test::Unit::TestCase
# --- Geocoder#configure method configuration --- # --- Geocoder#configure method configuration ---
def test_geocoder_configuration def test_geocoder_configuration
Geocoder.configure { |config| config.units = :mi } Geocoder.configure { config.units = :mi }
assert_equal Geocoder::Configuration.units, :mi assert_equal Geocoder::Configuration.units, :mi
distance = Geocoder::Calculations.distance_between([0,0], [0,1]).round distance = Geocoder::Calculations.distance_between([0,0], [0,1]).round
......
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