From 268f3d54eb0c1e01db610c970df59bf08bb96242 Mon Sep 17 00:00:00 2001
From: Anderson Bravalheri <andersonbravalheri@gmail.com>
Date: Thu, 21 Jul 2011 03:05:45 -0300
Subject: [PATCH] Creating a config generator for Geocoder.

---
 lib/generators/config.rb                | 12 ++++++++++++
 lib/generators/templates/initializer.rb | 25 +++++++++++++++++++++++++
 lib/geocoder/configuration.rb           |  4 ++--
 3 files changed, 39 insertions(+), 2 deletions(-)
 create mode 100644 lib/generators/config.rb
 create mode 100644 lib/generators/templates/initializer.rb

diff --git a/lib/generators/config.rb b/lib/generators/config.rb
new file mode 100644
index 00000000..2bafead5
--- /dev/null
+++ b/lib/generators/config.rb
@@ -0,0 +1,12 @@
+module Geocoder
+  class ConfigGenerator < Rails::Generators::Base
+    source_root File.expand_path("../templates", __FILE__)
+
+    desc "This generator creates an initializer file at config/initializers, " +
+         "with the default configuration options for Geocoder."
+    def add_initializer
+      template "initializer.rb", "config/initializers/geocoder.rb"
+    end
+  end
+end
+
diff --git a/lib/generators/templates/initializer.rb b/lib/generators/templates/initializer.rb
new file mode 100644
index 00000000..0401d015
--- /dev/null
+++ b/lib/generators/templates/initializer.rb
@@ -0,0 +1,25 @@
+Geocoder.configure do
+  ## Configurable parameters: if you wish to change some configurable
+  ## behaviour in Geocoder, feel free to uncomment the following lines
+  ## and provide custom parameters.
+
+  # 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
+  # config.units  = :mi        # :km for kilometers or :mi for miles
+  # config.method = :linear    # :spherical or :linear
+end
+
diff --git a/lib/geocoder/configuration.rb b/lib/geocoder/configuration.rb
index 867a4727..5ae37bce 100644
--- a/lib/geocoder/configuration.rb
+++ b/lib/geocoder/configuration.rb
@@ -28,8 +28,8 @@ module Geocoder
   #     config.always_raise = []
   #
   #     # Calculation options
-  #     @units  = :mi        # :km for kilometers or :mi for miles
-  #     @method = :linear    # :spherical or :linear
+  #     config.units  = :mi        # :km for kilometers or :mi for miles
+  #     config.method = :linear    # :spherical or :linear
   #   end
   #
   # @example Using +Geocoder::Configuration+ class directly, like in:
-- 
GitLab