rails-geocoder 0.9.0 → 0.9.1

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.9.1 (2010 May 4)
6
+
7
+ * Use scope instead of named_scope in Rails 3.
8
+
5
9
  == 0.9.0 (2010 Apr 2)
6
10
 
7
11
  * Fix bug in PostgreSQL support (caused "PGError: ERROR: column "distance" does not exist"), reported by developish.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = Geocoder
2
2
 
3
- Geocoder adds object geocoding and database-agnostic distance calculations to Ruby on Rails. It's as simple as calling <tt>fetch_coordinates!</tt> on your objects, and then using a named scope like <tt>Venue.near("Billings, MT")</tt>.
3
+ Geocoder adds object geocoding and database-agnostic distance calculations to Ruby on Rails. It's as simple as calling <tt>fetch_coordinates!</tt> on your objects, and then using a scope like <tt>Venue.near("Billings, MT")</tt>.
4
4
 
5
5
  Geocoder does not rely on proprietary database functions so finding geocoded objects in a given area is easily done using out-of-the-box MySQL or even SQLite.
6
6
 
@@ -9,6 +9,8 @@ Geocoder does not rely on proprietary database functions so finding geocoded obj
9
9
 
10
10
  == 1. Install
11
11
 
12
+ === a. Rails 2
13
+
12
14
  Install either as a plugin:
13
15
 
14
16
  script/plugin install git://github.com/alexreisner/geocoder.git
@@ -22,6 +24,21 @@ or as a gem:
22
24
  sudo rake gems:install
23
25
 
24
26
 
27
+ === b. Rails 3
28
+
29
+ Install either as a plugin:
30
+
31
+ rails plugin install git://github.com/alexreisner/geocoder.git
32
+
33
+ or as a gem:
34
+
35
+ # add to Gemfile:
36
+ gem "rails-geocoder", :require => "geocoder"
37
+
38
+ # at command prompt:
39
+ bundle install
40
+
41
+
25
42
  == 2. Configure
26
43
 
27
44
  A) Get a Google Maps API key (see http://code.google.com/apis/maps/signup.html) and store it in a constant:
@@ -61,7 +78,7 @@ Once +obj+ is geocoded you can do things like this:
61
78
  obj.nearbys(30) # other objects within 30 miles
62
79
  obj.distance_to(40.714, -100.234) # distance to arbitrary point
63
80
 
64
- To find objects by location, use the following named scopes:
81
+ To find objects by location, use the following scopes:
65
82
 
66
83
  Venue.near('Omaha, NE, US', 20) # venues within 20 miles of Omaha
67
84
  Venue.near([40.71, 100.23], 20) # venues within 20 miles of a point
@@ -106,7 +123,7 @@ Please see the code for more methods and detailed information about arguments (e
106
123
 
107
124
  == SQLite
108
125
 
109
- SQLite's lack of trigonometric functions means Geocoder's default implementation of the +near+ method (named scope) does not work. When using SQLite, Geocoder will automatically use a less accurate algorithm for finding objects near a given point. Results of this algorithm should not be trusted too much as it will return objects that are outside the given radius.
126
+ SQLite's lack of trigonometric functions means Geocoder's default implementation of the +near+ method (scope) does not work. When using SQLite, Geocoder will automatically use a less accurate algorithm for finding objects near a given point. Results of this algorithm should not be trusted too much as it will return objects that are outside the given radius.
110
127
 
111
128
 
112
129
  === Discussion
@@ -119,7 +136,7 @@ There are few options for finding objects near a given point in SQLite without i
119
136
 
120
137
  3. If you have a large number of objects (so you can't use approach #2) and you need accurate results (better than approach #1 will give), you can use a combination of the two. Get all the objects within a square around your center point, and then eliminate the ones that are too far away using <tt>Geocoder.distance_between</tt>.
121
138
 
122
- Because Geocoder needs to provide this functionality as a named scope, we must go with option #1, but feel free to implement #2 or #3 if you need more accuracy.
139
+ Because Geocoder needs to provide this functionality as a scope, we must go with option #1, but feel free to implement #2 or #3 if you need more accuracy.
123
140
 
124
141
 
125
142
  == To-do List
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.0
1
+ 0.9.1
data/lib/geocoder.rb CHANGED
@@ -12,22 +12,22 @@ module Geocoder
12
12
  base.extend ClassMethods
13
13
  base.class_eval do
14
14
 
15
- # named scope: geocoded objects
16
- named_scope :geocoded,
15
+ # scope: geocoded objects
16
+ send(Geocoder.scope_method_name, :geocoded,
17
17
  :conditions => "#{geocoder_options[:latitude]} IS NOT NULL " +
18
- "AND #{geocoder_options[:longitude]} IS NOT NULL"
18
+ "AND #{geocoder_options[:longitude]} IS NOT NULL")
19
19
 
20
- # named scope: not-geocoded objects
21
- named_scope :not_geocoded,
20
+ # scope: not-geocoded objects
21
+ send(Geocoder.scope_method_name, :not_geocoded,
22
22
  :conditions => "#{geocoder_options[:latitude]} IS NULL " +
23
- "OR #{geocoder_options[:longitude]} IS NULL"
23
+ "OR #{geocoder_options[:longitude]} IS NULL")
24
24
 
25
25
  ##
26
26
  # Find all objects within a radius (in miles) of the given location
27
27
  # (address string). Location (the first argument) may be either a string
28
28
  # to geocode or an array of coordinates (<tt>[lat,long]</tt>).
29
29
  #
30
- named_scope :near, lambda{ |location, *args|
30
+ send(Geocoder.scope_method_name, :near, lambda{ |location, *args|
31
31
  latitude, longitude = location.is_a?(Array) ?
32
32
  location : Geocoder.fetch_coordinates(location)
33
33
  if latitude and longitude
@@ -35,7 +35,7 @@ module Geocoder
35
35
  else
36
36
  {}
37
37
  end
38
- }
38
+ })
39
39
  end
40
40
  end
41
41
 
@@ -65,7 +65,7 @@ module Geocoder
65
65
  private # ----------------------------------------------------------------
66
66
 
67
67
  ##
68
- # Named scope options hash for use with a database that supports POWER(),
68
+ # Scope options hash for use with a database that supports POWER(),
69
69
  # SQRT(), PI(), and trigonometric functions (SIN(), COS(), and ASIN()).
70
70
  #
71
71
  # Taken from the excellent tutorial at:
@@ -93,7 +93,7 @@ module Geocoder
93
93
  end
94
94
 
95
95
  ##
96
- # Named scope options hash for use with a database without trigonometric
96
+ # Scope options hash for use with a database without trigonometric
97
97
  # functions, like SQLite. Approach is to find objects within a square
98
98
  # rather than a circle, so results are very approximate (will include
99
99
  # objects outside the given radius).
@@ -164,7 +164,7 @@ module Geocoder
164
164
 
165
165
  ##
166
166
  # Get other geocoded objects within a given radius (in miles). Takes a
167
- # radius (in miles) and options for passing to the +near+ named scope
167
+ # radius (in miles) and options for passing to the +near+ scope
168
168
  # (<tt>:order</tt>, <tt>:limit</tt>, and <tt>:offset</tt>).
169
169
  #
170
170
  def nearbys(radius = 20, options = {})
@@ -330,6 +330,13 @@ module Geocoder
330
330
  return nil
331
331
  end
332
332
  end
333
+
334
+ ##
335
+ # Name of the ActiveRecord scope method.
336
+ #
337
+ def self.scope_method_name
338
+ Rails.version.starts_with?("3") ? :scope : :named_scope
339
+ end
333
340
  end
334
341
 
335
342
  ##
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails-geocoder}
8
- s.version = "0.9.0"
8
+ s.version = "0.9.1"
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"]
12
- s.date = %q{2010-04-02}
12
+ s.date = %q{2010-05-04}
13
13
  s.description = %q{Geocoder adds object geocoding and database-agnostic distance calculations to Ruby on Rails. It does not rely on proprietary database functions so finding geocoded objects in a given area is easily done using out-of-the-box MySQL or even SQLite.}
14
14
  s.email = %q{alex@alexreisner.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 0
9
- version: 0.9.0
8
+ - 1
9
+ version: 0.9.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alex Reisner
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-02 00:00:00 -04:00
17
+ date: 2010-05-04 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20