From ed126c65179d6268c2a45680029fb6a089c0491c Mon Sep 17 00:00:00 2001
From: Alex Reisner <alex@alexreisner.com>
Date: Thu, 5 May 2011 22:39:02 -0400
Subject: [PATCH] Remove deprecation warnings and legacy support.

---
 lib/geocoder.rb                             | 34 +----------
 lib/geocoder/calculations.rb                | 25 ++-------
 lib/geocoder/configuration.rb               |  7 ---
 lib/geocoder/lookups/base.rb                |  7 +--
 lib/geocoder/stores/active_record.rb        |  9 +--
 lib/geocoder/stores/active_record_legacy.rb | 62 ---------------------
 lib/geocoder/stores/base.rb                 | 12 +---
 7 files changed, 12 insertions(+), 144 deletions(-)
 delete mode 100644 lib/geocoder/stores/active_record_legacy.rb

diff --git a/lib/geocoder.rb b/lib/geocoder.rb
index d98b76b5..928bc637 100644
--- a/lib/geocoder.rb
+++ b/lib/geocoder.rb
@@ -11,32 +11,8 @@ module Geocoder
   ##
   # Search for information about an address or a set of coordinates.
   #
-  def search(query, *args)
-    # convert coordinates as separate arguments to an array
-    if query.is_a?(Numeric) and args.first.is_a?(Numeric)
-      warn "DEPRECATION WARNING: Instead of passing latitude/longitude as separate arguments to the search method, please pass an array: [#{query},#{args.first}]. The old argument format will not be supported in Geocoder v.1.0."
-      query = [query, args.first]
-    end
-    if blank_query?(query)
-      results = []
-    else
-      results = lookup(query).search(query)
-    end
-    results.instance_eval do
-      def warn_search_deprecation(attr)
-        warn "DEPRECATION WARNING: Geocoder.search now returns an array of Geocoder::Result objects. " +
-          "Calling '%s' directly on the returned array will cause an exception in Geocoder v1.0." % attr
-      end
-
-      def coordinates; warn_search_deprecation('coordinates'); first.coordinates if first; end
-      def latitude; warn_search_deprecation('latitude'); first.latitude if first; end
-      def longitude; warn_search_deprecation('longitude'); first.longitude if first; end
-      def address; warn_search_deprecation('address'); first.address if first; end
-      def city; warn_search_deprecation('city'); first.city if first; end
-      def country; warn_search_deprecation('country'); first.country if first; end
-      def country_code; warn_search_deprecation('country_code'); first.country_code if first; end
-    end
-    return results
+  def search(query)
+    blank_query?(query) ? [] : lookup(query).search(query)
   end
 
   ##
@@ -52,11 +28,7 @@ module Geocoder
   # Look up the address of the given coordinates ([lat,lon])
   # or IP address (string).
   #
-  def address(query, *args)
-    if lon = args.first
-      warn "DEPRECATION WARNING: Instead of passing latitude/longitude as separate arguments to the address method, please pass an array: [#{query},#{args.first}]. The old argument format will not be supported in Geocoder v.1.0."
-      query = [query, lon]
-    end
+  def address(query)
     if (results = search(query)).size > 0
       results.first.address
     end
diff --git a/lib/geocoder/calculations.rb b/lib/geocoder/calculations.rb
index 7aa0b4b0..abc8b947 100644
--- a/lib/geocoder/calculations.rb
+++ b/lib/geocoder/calculations.rb
@@ -51,13 +51,7 @@ module Geocoder
     #
     # * <tt>:units</tt> - <tt>:mi</tt> (default) or <tt>:km</tt>
     #
-    def distance_between(point1, point2, options = {}, *args)
-      if args.size > 0
-        warn "DEPRECATION WARNING: Instead of passing lat1/lon1/lat2/lon2 as separate arguments to the distance_between method, please pass two two-element arrays: [#{point1},#{point2}], [#{options}, #{args.first}]. The old argument format will not be supported in Geocoder v.1.0."
-        point1 = [point1, point2]
-        point2 = [options, args.shift]
-        options = args.shift || {}
-      end
+    def distance_between(point1, point2, options = {})
 
       # set default options
       options[:units] ||= :mi
@@ -95,14 +89,9 @@ module Geocoder
     #
     # Based on: http://www.movable-type.co.uk/scripts/latlong.html
     #
-    def bearing_between(point1, point2, options = {}, *args)
-      if args.size > 0
-        warn "DEPRECATION WARNING: Instead of passing lat1/lon1/lat2/lon2 as separate arguments to the bearing_between method, please pass two two-element arrays: [#{point1},#{point2}], [#{options}, #{args.first}]. The old argument format will not be supported in Geocoder v.1.0."
-        point1 = [point1, point2]
-        point2 = [options, args.shift]
-        options = args.shift || {}
-      end
+    def bearing_between(point1, point2, options = {})
 
+      # set default options
       options[:method] = :linear unless options[:method] == :spherical
 
       # convert to coordinate arrays
@@ -190,13 +179,7 @@ module Geocoder
     #
     # * <tt>:units</tt> - <tt>:mi</tt> (default) or <tt>:km</tt>
     #
-    def bounding_box(point, radius, options = {}, *args)
-      if point.is_a?(Numeric)
-        warn "DEPRECATION WARNING: Instead of passing latitude/longitude as separate arguments to the bounding_box method, please pass an array [#{point},#{radius}], a geocoded object, or a geocodable address (string). The old argument format will not be supported in Geocoder v.1.0."
-        point   = [point, radius]
-        radius  = options
-        options = args.first || {}
-      end
+    def bounding_box(point, radius, options = {})
       lat,lon = extract_coordinates(point)
       radius  = radius.to_f
       units   = options[:units] || :mi
diff --git a/lib/geocoder/configuration.rb b/lib/geocoder/configuration.rb
index 3fefc7fe..bc5e2b98 100644
--- a/lib/geocoder/configuration.rb
+++ b/lib/geocoder/configuration.rb
@@ -38,13 +38,6 @@ module Geocoder
       eval("def self.#{o}=(obj); @@#{o} = obj; end")
     end
 
-    # legacy support
-    def self.yahoo_app_id=(value)
-      warn "DEPRECATION WARNING: Geocoder's 'yahoo_app_id' setting has been replaced by 'api_key'. " +
-        "This method will be removed in Geocoder v1.0."
-      @@api_key = value
-    end
-
     ##
     # Set all values to default.
     #
diff --git a/lib/geocoder/lookups/base.rb b/lib/geocoder/lookups/base.rb
index 497f73ed..9d58c7e9 100644
--- a/lib/geocoder/lookups/base.rb
+++ b/lib/geocoder/lookups/base.rb
@@ -22,12 +22,7 @@ module Geocoder
       # "205.128.54.202") for geocoding, or coordinates (latitude, longitude)
       # for reverse geocoding. Returns an array of <tt>Geocoder::Result</tt>s.
       #
-      def search(query, *args)
-        # convert coordinates as separate arguments to an array
-        if query.is_a?(Numeric) and args.first.is_a?(Numeric)
-          warn "DEPRECATION WARNING: Instead of passing latitude/longitude as separate arguments to the search method, please pass an array: [#{query},#{args.first}]. The old argument format will not be supported in Geocoder v.1.0."
-          query = [query, args.first]
-        end
+      def search(query)
 
         # if coordinates given as string, turn into array
         query = query.split(/\s*,\s*/) if coordinates?(query)
diff --git a/lib/geocoder/stores/active_record.rb b/lib/geocoder/stores/active_record.rb
index dc4cd2d8..d7a37cee 100644
--- a/lib/geocoder/stores/active_record.rb
+++ b/lib/geocoder/stores/active_record.rb
@@ -1,5 +1,4 @@
 require 'geocoder/stores/base'
-require 'geocoder/stores/active_record_legacy'
 
 ##
 # Add geocoding functionality to any ActiveRecord object.
@@ -7,7 +6,6 @@ require 'geocoder/stores/active_record_legacy'
 module Geocoder::Store
   module ActiveRecord
     include Base
-    include ActiveRecord::Legacy
 
     ##
     # Implementation of 'included' hook method.
@@ -180,9 +178,6 @@ module Geocoder::Store
           conditions[0] << " AND #{table_name}.id != ?"
           conditions << obj.id
         end
-        if options[:limit] || options[:offset]
-          warn "DEPRECATION WARNING: The :limit and :offset options to Geocoder's 'near' method are deprecated and will be removed in Geocoder v1.0. Please specify these options using ARel relations instead, for example: Place.near(...).limit(10).offset(20)."
-        end
         {
           :group  => columns.map{ |c| "#{table_name}.#{c.name}" }.join(','),
           :order  => options[:order],
@@ -208,7 +203,7 @@ module Geocoder::Store
       end
     end
 
-    #alias_method :fetch_coordinates, :geocode
+    alias_method :fetch_coordinates, :geocode
 
     ##
     # Look up address and assign to +address+ attribute (or other as specified
@@ -224,6 +219,6 @@ module Geocoder::Store
       end
     end
 
-    #alias_method :fetch_address, :reverse_geocode
+    alias_method :fetch_address, :reverse_geocode
   end
 end
diff --git a/lib/geocoder/stores/active_record_legacy.rb b/lib/geocoder/stores/active_record_legacy.rb
deleted file mode 100644
index 6a28fd56..00000000
--- a/lib/geocoder/stores/active_record_legacy.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-module Geocoder::Store::ActiveRecord
-  module Legacy
-
-    ##
-    # Fetch coordinates and update (save) +latitude+ and +longitude+ data.
-    #
-    def fetch_coordinates!
-      warn "DEPRECATION WARNING: The 'fetch_coordinates!' method is deprecated and will be removed in geocoder v1.0. " +
-        "Please use 'geocode' instead and then save your objects manually."
-      do_lookup(false) do |o,rs|
-        r = rs.first
-        unless r.latitude.nil? or r.longitude.nil?
-          o.send :update_attribute, self.class.geocoder_options[:latitude],  r.latitude
-          o.send :update_attribute, self.class.geocoder_options[:longitude], r.longitude
-        end
-        r.coordinates
-      end
-    end
-
-    def fetch_coordinates(*args)
-      warn "DEPRECATION WARNING: The 'fetch_coordinates' method will cease taking " +
-        "an argument in geocoder v1.0. Please save your objects manually." if args.size > 0
-      do_lookup(false) do |o,rs|
-        r = rs.first
-        unless r.latitude.nil? or r.longitude.nil?
-          method = ((args.size > 0 && args.first) ? "update" : "write" ) + "_attribute"
-          o.send method, self.class.geocoder_options[:latitude],  r.latitude
-          o.send method, self.class.geocoder_options[:longitude], r.longitude
-        end
-        r.coordinates
-      end
-    end
-
-    ##
-    # Fetch address and update (save) +address+ data.
-    #
-    def fetch_address!
-      warn "DEPRECATION WARNING: The 'fetch_address!' method is deprecated and will be removed in geocoder v1.0. " +
-        "Please use 'reverse_geocode' instead and then save your objects manually."
-      do_lookup(true) do |o,rs|
-        r = rs.first
-        unless r.address.nil?
-          o.send :update_attribute, self.class.geocoder_options[:fetched_address], r.address
-        end
-        r.address
-      end
-    end
-
-    def fetch_address(*args)
-      warn "DEPRECATION WARNING: The 'fetch_address' method will cease taking " +
-        "an argument in geocoder v1.0. Please save your objects manually." if args.size > 0
-      do_lookup(true) do |o,rs|
-        r = rs.first
-        unless r.latitude.nil? or r.longitude.nil?
-          method = ((args.size > 0 && args.first) ? "update" : "write" ) + "_attribute"
-          o.send method, self.class.geocoder_options[:fetched_address], r.address
-        end
-        r.address
-      end
-    end
-  end
-end
diff --git a/lib/geocoder/stores/base.rb b/lib/geocoder/stores/base.rb
index e0f90942..13a0a353 100644
--- a/lib/geocoder/stores/base.rb
+++ b/lib/geocoder/stores/base.rb
@@ -22,14 +22,10 @@ module Geocoder
       # the point. Also takes a symbol specifying the units
       # (:mi or :km; default is :mi).
       #
-      def distance_to(point, *args)
-        if point.is_a?(Numeric) and args[0].is_a?(Numeric)
-          warn "DEPRECATION WARNING: Instead of passing latitude/longitude as separate arguments to the distance_to/from method, please pass an array [#{point},#{args[0]}], a geocoded object, or a geocodable address (string). The old argument format will not be supported in Geocoder v.1.0."
-          point = [point, args.shift]
-        end
+      def distance_to(point, units = :mi)
         return nil unless geocoded?
         Geocoder::Calculations.distance_between(
-          to_coordinates, point, :units => args.pop || :mi)
+          to_coordinates, point, :units => units)
       end
 
       alias_method :distance_from, :distance_to
@@ -62,10 +58,6 @@ module Geocoder
       #
       def nearbys(radius = 20, options = {})
         return [] unless geocoded?
-        if options.is_a?(Symbol)
-          options = {:units => options}
-          warn "DEPRECATION WARNING: The units argument to the nearbys method has been replaced with an options hash (same options hash as the near scope). You should instead call: obj.nearbys(#{radius}, :units => #{options[:units]}). The old syntax will not be supported in Geocoder v1.0."
-        end
         options.merge!(:exclude => self)
         self.class.near(self, radius, options)
       end
-- 
GitLab