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

Remove deprecation warnings and legacy support.

parent dee81642
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......
......@@ -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.
#
......
......@@ -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)
......
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
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
......@@ -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
......
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