rails-geocoder 0.9.1 → 0.9.2
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 +4 -0
- data/VERSION +1 -1
- data/lib/geocoder.rb +21 -20
- data/rails-geocoder.gemspec +2 -2
- metadata +3 -3
data/CHANGELOG.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.2
|
data/lib/geocoder.rb
CHANGED
@@ -51,7 +51,7 @@ module Geocoder
|
|
51
51
|
#
|
52
52
|
# +order+ :: column(s) for ORDER BY SQL clause
|
53
53
|
# +limit+ :: number of records to return (for LIMIT SQL clause)
|
54
|
-
# +offset+ :: number of records to skip (for
|
54
|
+
# +offset+ :: number of records to skip (for OFFSET SQL clause)
|
55
55
|
#
|
56
56
|
def near_scope_options(latitude, longitude, radius = 20, options = {})
|
57
57
|
if ActiveRecord::Base.connection.adapter_name == "SQLite"
|
@@ -81,15 +81,13 @@ module Geocoder
|
|
81
81
|
"COS(#{lat_attr} * PI() / 180) * " +
|
82
82
|
"POWER(SIN((#{longitude} - #{lon_attr}) * " +
|
83
83
|
"PI() / 180 / 2), 2) ))"
|
84
|
-
|
84
|
+
default_near_scope_options(latitude, longitude, radius, options).merge(
|
85
85
|
:select => "*, #{distance} AS distance",
|
86
86
|
:conditions => \
|
87
87
|
["#{lat_attr} BETWEEN ? AND ? AND #{lon_attr} BETWEEN ? AND ?"] +
|
88
88
|
coordinate_bounds(latitude, longitude, radius),
|
89
|
-
:having => "#{distance} <= #{radius}"
|
90
|
-
|
91
|
-
:limit => limit_clause(options)
|
92
|
-
}
|
89
|
+
:having => "#{distance} <= #{radius}"
|
90
|
+
)
|
93
91
|
end
|
94
92
|
|
95
93
|
##
|
@@ -101,12 +99,21 @@ module Geocoder
|
|
101
99
|
def approx_near_scope_options(latitude, longitude, radius, options)
|
102
100
|
lat_attr = geocoder_options[:latitude]
|
103
101
|
lon_attr = geocoder_options[:longitude]
|
104
|
-
|
102
|
+
default_near_scope_options(latitude, longitude, radius, options).merge(
|
105
103
|
:conditions => \
|
106
104
|
["#{lat_attr} BETWEEN ? AND ? AND #{lon_attr} BETWEEN ? AND ?"] +
|
107
|
-
coordinate_bounds(latitude, longitude, radius)
|
105
|
+
coordinate_bounds(latitude, longitude, radius)
|
106
|
+
)
|
107
|
+
end
|
108
|
+
|
109
|
+
##
|
110
|
+
# Options used for any near-like scope.
|
111
|
+
#
|
112
|
+
def default_near_scope_options(latitude, longitude, radius, options)
|
113
|
+
{
|
108
114
|
:order => options[:order],
|
109
|
-
:limit =>
|
115
|
+
:limit => options[:limit],
|
116
|
+
:offset => options[:offset]
|
110
117
|
}
|
111
118
|
end
|
112
119
|
|
@@ -125,16 +132,6 @@ module Geocoder
|
|
125
132
|
longitude + (radius / factor)
|
126
133
|
]
|
127
134
|
end
|
128
|
-
|
129
|
-
##
|
130
|
-
# Build the limit clause for a query based on the same options hash
|
131
|
-
# passed to the x_near_scope_options methods.
|
132
|
-
#
|
133
|
-
def limit_clause(options)
|
134
|
-
if options[:limit] or options[:offset]
|
135
|
-
"#{options[:offset].to_i},#{options[:limit].to_i}"
|
136
|
-
end
|
137
|
-
end
|
138
135
|
end
|
139
136
|
|
140
137
|
##
|
@@ -335,7 +332,11 @@ module Geocoder
|
|
335
332
|
# Name of the ActiveRecord scope method.
|
336
333
|
#
|
337
334
|
def self.scope_method_name
|
338
|
-
|
335
|
+
begin
|
336
|
+
Rails.version.starts_with?("3") ? :scope : :named_scope
|
337
|
+
rescue NameError
|
338
|
+
:named_scope
|
339
|
+
end
|
339
340
|
end
|
340
341
|
end
|
341
342
|
|
data/rails-geocoder.gemspec
CHANGED
@@ -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.
|
8
|
+
s.version = "0.9.2"
|
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-
|
12
|
+
s.date = %q{2010-06-03}
|
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
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 2
|
9
|
+
version: 0.9.2
|
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-
|
17
|
+
date: 2010-06-03 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|