rails-geocoder 0.8.3 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.rdoc CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  Per-release changes to Geocoder.
4
4
 
5
+ == 0.8.4 (2009 Oct 23)
6
+
7
+ * Deprecate <tt>find_near</tt> class method in favor of +near+ named scope.
8
+
5
9
  == 0.8.3 (2009 Oct 23)
6
10
 
7
11
  * Update Google URL query string parameter to reflect recent changes in Google's API.
data/README.rdoc CHANGED
@@ -44,22 +44,22 @@ If your model has +address+, +city+, +state+, and +country+ attributes your +loc
44
44
 
45
45
  == 3. Use
46
46
 
47
- Assuming +Venue+ is a geocoded model:
47
+ Assuming +Venue+ is a geocoded model, it has the following named scopes:
48
48
 
49
- Venue.find_near('Omaha, NE, US', 20) # venues within 20 miles of Omaha
50
- Venue.find_near([40.71, 100.23], 20) # venues within 20 miles of a point
51
- Venue.geocoded # venues with coordinates
52
- Venue.not_geocoded # venues without coordinates
49
+ Venue.near('Omaha, NE, US', 20) # venues within 20 miles of Omaha
50
+ Venue.near([40.71, 100.23], 20) # venues within 20 miles of a point
51
+ Venue.geocoded # venues with coordinates
52
+ Venue.not_geocoded # venues without coordinates
53
53
 
54
54
  Assuming +obj+ has a valid string for its +location+:
55
55
 
56
- obj.fetch_coordinates # returns coordinates [lat, lon]
57
- obj.fetch_coordinates! # also writes coordinates to object
56
+ obj.fetch_coordinates # returns coordinates [lat, lon]
57
+ obj.fetch_coordinates! # also writes coordinates to object
58
58
 
59
59
  Assuming +obj+ is geocoded (has latitude and longitude):
60
60
 
61
- obj.nearbys(30) # other objects within 30 miles
62
- obj.distance_to(40.714, -100.234) # distance to arbitrary point
61
+ obj.nearbys(30) # other objects within 30 miles
62
+ obj.distance_to(40.714, -100.234) # distance to arbitrary point
63
63
 
64
64
  Some utility methods are also available:
65
65
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.3
1
+ 0.8.4
data/lib/geocoder.rb CHANGED
@@ -11,15 +11,30 @@ module Geocoder
11
11
  base.class_eval do
12
12
 
13
13
  # named scope: geocoded objects
14
- named_scope :geocoded,
15
- :conditions => "#{geocoder_options[:latitude]} IS NOT NULL " +
16
- "AND #{geocoder_options[:longitude]} IS NOT NULL"
14
+ named_scope :geocoded,
15
+ :conditions => "#{geocoder_options[:latitude]} IS NOT NULL " +
16
+ "AND #{geocoder_options[:longitude]} IS NOT NULL"
17
17
 
18
18
  # named scope: not-geocoded objects
19
- named_scope :not_geocoded,
20
- :conditions => "#{geocoder_options[:latitude]} IS NULL " +
21
- "OR #{geocoder_options[:longitude]} IS NULL"
22
- end
19
+ named_scope :not_geocoded,
20
+ :conditions => "#{geocoder_options[:latitude]} IS NULL " +
21
+ "OR #{geocoder_options[:longitude]} IS NULL"
22
+
23
+ ##
24
+ # Find all objects within a radius (in miles) of the given location
25
+ # (address string). Location (the first argument) may be either a string
26
+ # to geocode or an array of coordinates (<tt>[lat,long]</tt>).
27
+ #
28
+ named_scope :near, lambda{ |location, *args|
29
+ latitude, longitude = location.is_a?(Array) ?
30
+ location : Geocoder.fetch_coordinates(location)
31
+ if latitude and longitude
32
+ find_near_options(latitude, longitude, *args)
33
+ else
34
+ {}
35
+ end
36
+ }
37
+ end
23
38
  end
24
39
 
25
40
  ##
@@ -28,15 +43,12 @@ module Geocoder
28
43
  module ClassMethods
29
44
 
30
45
  ##
31
- # Find all objects within a radius (in miles) of the given location
32
- # (address string). Location (the first argument) may be either a string
33
- # to geocode or an array of coordinates (<tt>[lat,long]</tt>).
46
+ # DEPRECATED: Please use the +near+ method/named scope instead.
34
47
  #
35
48
  def find_near(location, radius = 20, options = {})
36
- latitude, longitude = location.is_a?(Array) ?
37
- location : Geocoder.fetch_coordinates(location)
38
- return [] unless (latitude and longitude)
39
- all(find_near_options(latitude, longitude, radius, options))
49
+ warn "Geocoder deprecation warning: the 'find_near' class method is " +
50
+ "deprecated, please use the 'near' method, which is a named scope."
51
+ near(location, radius, options)
40
52
  end
41
53
 
42
54
  ##
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails-geocoder}
8
- s.version = "0.8.3"
8
+ s.version = "0.8.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alex Reisner"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-geocoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Reisner