geokit-rails 2.2.0 → 2.3.0
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.
Potentially problematic release.
This version of geokit-rails might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +4 -4
- data/CHANGELOG.md +24 -0
- data/README.markdown +18 -25
- data/lib/geokit-rails/acts_as_mappable.rb +7 -4
- data/lib/geokit-rails/adapters/sqlserver.rb +19 -17
- data/lib/geokit-rails/geocoder_control.rb +6 -7
- data/lib/geokit-rails/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48ca6ff9da9db809b5364c5da86253f349dc5aff
|
4
|
+
data.tar.gz: faf83c4907ad40f8c14b1431309d9db0b009fba7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7aeacd224c2d14b57a37a1666dc514002d4baf6bf3d20a03f6a212a05bcf9920dc4f5c2cc72fa0798dc42ab6c1912dec185e0616edf41f0070806cfaf04c8060
|
7
|
+
data.tar.gz: ef046a2677870e71be5ecdf2c0bf8e90f979d858efb237bea8ec531644473af9a339f0ec413bfcc37affb19187bdaaaaf7272567a96fff3a32ed062b3ba4c642
|
data/.travis.yml
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 1.9
|
4
3
|
- 2.0
|
5
4
|
- 2.1
|
6
5
|
- 2.2
|
6
|
+
- 2.3
|
7
7
|
gemfile:
|
8
8
|
- gemfiles/rails3.gemfile
|
9
9
|
- gemfiles/rails4.gemfile
|
10
10
|
matrix:
|
11
11
|
exclude:
|
12
|
-
- rvm: 1.9
|
13
|
-
gemfile: gemfiles/rails4.gemfile
|
14
12
|
- rvm: 2.2
|
15
13
|
gemfile: gemfiles/rails3.gemfile
|
14
|
+
- rvm: 2.3
|
15
|
+
gemfile: gemfiles/rails3.gemfile
|
16
16
|
script: "bundle exec rake coverage"
|
17
17
|
before_install:
|
18
18
|
- gem install bundler
|
19
|
-
|
20
19
|
bundler_args: --retry 5
|
20
|
+
sudo: false
|
21
21
|
cache: bundler
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
## 2.3.0
|
2
|
+
|
3
|
+
* Drop ruby 1.9 and add 2.3 support
|
4
|
+
* Add an option to skip loading
|
5
|
+
* Remove excessive debug statement
|
6
|
+
|
7
|
+
## 2.2.0
|
8
|
+
|
9
|
+
* Add rails config aenerator
|
10
|
+
* Add NOT NULL checks for latitude and longitude, otherwise nonsense
|
11
|
+
values are being returned for distance calculations involving such
|
12
|
+
objects.
|
13
|
+
* Fix inconsistent case where retrieve_location_from_cookie_or_services
|
14
|
+
returned a Hash instead of a GeoLoc
|
15
|
+
* Speed up SQL with bounding box
|
16
|
+
* Tests against rails 4 & 5
|
17
|
+
|
18
|
+
## 2.1.0
|
19
|
+
|
20
|
+
* Add OracleEnhanced adapter
|
21
|
+
* Fix bug with custom latitude/longitude names
|
22
|
+
* BREAKING: Nearest and fathest return scopes not arrays
|
23
|
+
* Drop support for ruby 1.8/1.9
|
24
|
+
|
1
25
|
## 2.0.1
|
2
26
|
|
3
27
|
* Fix GeoKit naming compatibility
|
data/README.markdown
CHANGED
@@ -32,8 +32,15 @@ Then tell bundler to update the gems :
|
|
32
32
|
```sh
|
33
33
|
$ bundle install
|
34
34
|
```
|
35
|
+
Generate the configuration initializer:
|
36
|
+
|
37
|
+
```sh
|
38
|
+
$ rails g geokit_rails:install
|
39
|
+
```
|
40
|
+
|
41
|
+
Now, if you wish to use the various geocoding services, you can add your keys to the new initializer.
|
42
|
+
|
35
43
|
|
36
|
-
Last, consult the `important post-installation notes` section at the end of this document.
|
37
44
|
|
38
45
|
If you want to use geokit-rails in a Rails 2 application, just use the good old plugin ([geokit-rails](https://github.com/andre/geokit-rails)).
|
39
46
|
|
@@ -113,27 +120,21 @@ Once you've specified `acts_as_mappable`, a few scopes are available :
|
|
113
120
|
* `closest` and `farthest` find the closest or farthest record from the origin point
|
114
121
|
* `by_distance` finds records ordered by distance from the origin point
|
115
122
|
|
116
|
-
All these scopes
|
117
|
-
|
123
|
+
All of these scopes take a hash of options where the first parameter is simply
|
124
|
+
one of the possible options, without the name.
|
118
125
|
|
119
126
|
A few examples :
|
120
127
|
|
121
128
|
```ruby
|
122
129
|
Location.within(5, :origin => @somewhere)
|
123
|
-
# is the same as
|
124
|
-
Location.geo_scope(:within => 5, :origin => @somewhere)
|
125
130
|
```
|
126
131
|
|
127
132
|
```ruby
|
128
133
|
Location.in_range(2..5, :origin => @somewhere)
|
129
|
-
# is the same as
|
130
|
-
Location.geo_scope(:range => 2..5, :origin => @somewhere)
|
131
134
|
```
|
132
135
|
|
133
136
|
```ruby
|
134
137
|
Location.in_bounds([@south_west_point, @north_east_point], :origin => @somewhere)
|
135
|
-
# is the same as
|
136
|
-
Location.geo_scope(:bounds => [@south_west_point, @north_east_point], :origin => @somewhere)
|
137
138
|
```
|
138
139
|
|
139
140
|
The options can be :
|
@@ -141,13 +142,13 @@ The options can be :
|
|
141
142
|
`:origin` as a two-element array of latitude/longitude:
|
142
143
|
|
143
144
|
```ruby
|
144
|
-
Location.
|
145
|
+
Location.by_distance(:origin => [37.792,-122.393])
|
145
146
|
```
|
146
147
|
|
147
148
|
`:origin` as a geocodeable string:
|
148
149
|
|
149
150
|
```ruby
|
150
|
-
Location.
|
151
|
+
Location.by_distance(:origin => '100 Spear st, San Francisco, CA')
|
151
152
|
```
|
152
153
|
|
153
154
|
`:origin` as an object which responds to `lat` and `lng` methods,
|
@@ -174,7 +175,7 @@ Location.within(5, :units => :kms, :origin => @somewhere)
|
|
174
175
|
@sw = Geokit::LatLng.new(32.91663,-96.982841)
|
175
176
|
@ne = Geokit::LatLng.new(32.96302,-96.919495)
|
176
177
|
@somewhere = Location.find(123456)
|
177
|
-
Location.
|
178
|
+
Location.within(:bounds => [@sw, @ne], :origin => @somewhere)
|
178
179
|
```
|
179
180
|
|
180
181
|
`:bounds` as a Geokit::Bounds object
|
@@ -182,7 +183,7 @@ Location.geo_scope(:bounds => [@sw, @ne], :origin => @somewhere)
|
|
182
183
|
```ruby
|
183
184
|
@bounds = Geokit::Bounds.new([32.91663,-96.982841], [32.96302,-96.919495])
|
184
185
|
@somewhere = Location.find(123456)
|
185
|
-
Location.
|
186
|
+
Location.within(:bounds => [@sw, @ne], :origin => @somewhere)
|
186
187
|
```
|
187
188
|
|
188
189
|
When using a point of reference or bounds, you leverage the power of Geokit
|
@@ -207,7 +208,7 @@ You can then chain these scope with any other or use a "calling" method like `fi
|
|
207
208
|
```ruby
|
208
209
|
Location.within(5, :origin => @somewhere).all
|
209
210
|
Location.within(5, :origin => @somewhere).count
|
210
|
-
Location.
|
211
|
+
Location.by_distance(:origin => [37.792,-122.393]).first
|
211
212
|
```
|
212
213
|
|
213
214
|
You can add `order` clauses in the chain as for any ActiveRecord query
|
@@ -226,10 +227,10 @@ Idem for the `limit` clause. In fact, `closest` and `farthest` are defined like
|
|
226
227
|
|
227
228
|
```ruby
|
228
229
|
def closest(options = {})
|
229
|
-
|
230
|
+
by_distance(options).limit(1)
|
230
231
|
end
|
231
232
|
def farthest(options = {})
|
232
|
-
|
233
|
+
by_distance({:reverse => true}.merge(options)).limit(1)
|
233
234
|
end
|
234
235
|
```
|
235
236
|
|
@@ -241,7 +242,7 @@ using the _distance_ column. I've tried many different ways to do this and didn'
|
|
241
242
|
One would expect to build a query like this :
|
242
243
|
|
243
244
|
```ruby
|
244
|
-
scoped = Location.
|
245
|
+
scoped = Location.by_distance(:origin => @somewhere)
|
245
246
|
scoped = scoped.where('distance <= 5')
|
246
247
|
results = scoped.all
|
247
248
|
```
|
@@ -717,11 +718,3 @@ GeoLoc represents an address or location which
|
|
717
718
|
has been geocoded. You can get the city, zipcode, street address, etc.
|
718
719
|
from a GeoLoc object. GeoLoc extends LatLng, so you also get lat/lng
|
719
720
|
AND the Mappable module goodness for free.
|
720
|
-
|
721
|
-
## IMPORTANT POST-INSTALLATION NOTES:
|
722
|
-
|
723
|
-
*1. The configuration file*: Geokit for Rails uses a configuration file in config/initializers.
|
724
|
-
You *must* add your own keys for the various geocoding services if you want to use geocoding. You can generate a sample initializer file by run:
|
725
|
-
```sh
|
726
|
-
$ rails g geokit_rails:install
|
727
|
-
```
|
@@ -11,6 +11,8 @@ module Geokit
|
|
11
11
|
extend ActiveSupport::Concern
|
12
12
|
|
13
13
|
module ClassMethods # :nodoc:
|
14
|
+
OPTION_SYMBOLS = [ :distance_column_name, :default_units, :default_formula, :lat_column_name, :lng_column_name, :qualified_lat_column_name, :qualified_lng_column_name, :skip_loading ]
|
15
|
+
|
14
16
|
def acts_as_mappable(options = {})
|
15
17
|
metaclass = (class << self; self; end)
|
16
18
|
|
@@ -21,20 +23,21 @@ module Geokit
|
|
21
23
|
|
22
24
|
if reflection = Geokit::ActsAsMappable.end_of_reflection_chain(self.through, self)
|
23
25
|
metaclass.instance_eval do
|
24
|
-
|
26
|
+
OPTION_SYMBOLS.each do |method_name|
|
25
27
|
define_method method_name do
|
26
28
|
reflection.klass.send(method_name)
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
30
32
|
else
|
31
|
-
cattr_accessor
|
33
|
+
cattr_accessor *OPTION_SYMBOLS
|
32
34
|
|
33
35
|
self.distance_column_name = options[:distance_column_name] || 'distance'
|
34
36
|
self.default_units = options[:default_units] || Geokit::default_units
|
35
37
|
self.default_formula = options[:default_formula] || Geokit::default_formula
|
36
38
|
self.lat_column_name = options[:lat_column_name] || 'lat'
|
37
39
|
self.lng_column_name = options[:lng_column_name] || 'lng'
|
40
|
+
self.skip_loading = options[:skip_loading]
|
38
41
|
self.qualified_lat_column_name = "#{table_name}.#{lat_column_name}"
|
39
42
|
self.qualified_lng_column_name = "#{table_name}.#{lng_column_name}"
|
40
43
|
|
@@ -105,7 +108,7 @@ module Geokit
|
|
105
108
|
# Re-init the klass after require
|
106
109
|
klass = Adapters.const_get(connection.adapter_name.camelcase)
|
107
110
|
end
|
108
|
-
klass.load(self) unless klass.loaded
|
111
|
+
klass.load(self) unless klass.loaded || skip_loading
|
109
112
|
klass.new(self)
|
110
113
|
rescue LoadError
|
111
114
|
raise UnsupportedAdapter, "`#{connection.adapter_name.downcase}` is not a supported adapter."
|
@@ -117,7 +120,7 @@ module Geokit
|
|
117
120
|
# Add bounding box to speed up SQL request.
|
118
121
|
bounds = formulate_bounds_from_distance(
|
119
122
|
options,
|
120
|
-
normalize_point_to_lat_lng(options[:origin]),
|
123
|
+
normalize_point_to_lat_lng(options[:origin]),
|
121
124
|
options[:units] || default_units)
|
122
125
|
with_latlng.where(bound_conditions(bounds)).
|
123
126
|
where(distance_conditions(options))
|
@@ -1,28 +1,30 @@
|
|
1
1
|
module Geokit
|
2
2
|
module Adapters
|
3
3
|
class SQLServer < Abstract
|
4
|
-
|
4
|
+
|
5
5
|
class << self
|
6
|
-
|
6
|
+
|
7
7
|
def load(klass)
|
8
|
-
klass.
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
klass.transaction do
|
9
|
+
klass.connection.execute <<-EOS
|
10
|
+
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[geokit_least]') and xtype in (N'FN', N'IF', N'TF'))
|
11
|
+
drop function [dbo].[geokit_least]
|
12
|
+
EOS
|
13
|
+
|
14
|
+
klass.connection.execute <<-EOS
|
15
|
+
CREATE FUNCTION [dbo].geokit_least (@value1 float,@value2 float) RETURNS float AS BEGIN
|
16
|
+
return (SELECT CASE WHEN @value1 < @value2 THEN @value1 ELSE @value2 END) END
|
17
|
+
EOS
|
18
|
+
end
|
17
19
|
self.loaded = true
|
18
20
|
end
|
19
|
-
|
21
|
+
|
20
22
|
end
|
21
|
-
|
23
|
+
|
22
24
|
def initialize(*args)
|
23
25
|
super(*args)
|
24
26
|
end
|
25
|
-
|
27
|
+
|
26
28
|
def sphere_distance_sql(lat, lng, multiplier)
|
27
29
|
%|
|
28
30
|
(ACOS([dbo].geokit_least(1,COS(#{lat})*COS(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*COS(RADIANS(#{qualified_lng_column_name}))+
|
@@ -30,14 +32,14 @@ module Geokit
|
|
30
32
|
SIN(#{lat})*SIN(RADIANS(#{qualified_lat_column_name}))))*#{multiplier})
|
31
33
|
|
|
32
34
|
end
|
33
|
-
|
35
|
+
|
34
36
|
def flat_distance_sql(origin, lat_degree_units, lng_degree_units)
|
35
37
|
%|
|
36
38
|
SQRT(POWER(#{lat_degree_units}*(#{origin.lat}-#{qualified_lat_column_name}),2)+
|
37
39
|
POWER(#{lng_degree_units}*(#{origin.lng}-#{qualified_lng_column_name}),2))
|
38
40
|
|
|
39
41
|
end
|
40
|
-
|
42
|
+
|
41
43
|
end
|
42
44
|
end
|
43
|
-
end
|
45
|
+
end
|
@@ -3,18 +3,17 @@ require 'active_support/concern'
|
|
3
3
|
module Geokit
|
4
4
|
module GeocoderControl
|
5
5
|
extend ActiveSupport::Concern
|
6
|
-
|
6
|
+
|
7
7
|
included do
|
8
|
-
if
|
9
|
-
|
10
|
-
elsif
|
11
|
-
|
8
|
+
if respond_to? :before_action
|
9
|
+
send :before_action, :set_geokit_domain
|
10
|
+
elsif respond_to? :before_filter
|
11
|
+
send :before_filter, :set_geokit_domain
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def set_geokit_domain
|
16
16
|
Geokit::Geocoders::domain = request.domain
|
17
|
-
logger.debug("Geokit is using the domain: #{Geokit::Geocoders::domain}")
|
18
17
|
end
|
19
18
|
end
|
20
19
|
end
|
data/lib/geokit-rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geokit-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Noack
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2017-08-08 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|
@@ -293,7 +293,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
293
293
|
version: '0'
|
294
294
|
requirements: []
|
295
295
|
rubyforge_project:
|
296
|
-
rubygems_version: 2.
|
296
|
+
rubygems_version: 2.5.2
|
297
297
|
signing_key:
|
298
298
|
specification_version: 4
|
299
299
|
summary: Geokit helpers for rails apps.
|