activerecord-postgres-earthdistance 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 693d1cb274f3a7106fbdc225fc4d837faec9cb35
|
4
|
+
data.tar.gz: 21874225968e12b05ca6e73acc6aa05bc3f860be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e93b59b3ecf2e5fcb2bf68d813d5fd6702a1f19a7b7850e36ef42911249c72ed60b0b0f8b7032979e5b986a2ccb97b4e52962b1f7fcaa0b532d79c901e4475c
|
7
|
+
data.tar.gz: daf84e9742146cb893ec708e85390f65d398ebefab8959621774530ebd72b6e9b6cd475acc4306d6377779c90cd02a5a87e8e28aee516d9f5ecd083828a6091b
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
activerecord-postgres-earthdistance (0.4.
|
4
|
+
activerecord-postgres-earthdistance (0.4.3)
|
5
5
|
pg
|
6
6
|
rails (>= 3.1)
|
7
7
|
rake
|
@@ -9,36 +9,36 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: http://rubygems.org/
|
11
11
|
specs:
|
12
|
-
actionmailer (4.2.
|
13
|
-
actionpack (= 4.2.
|
14
|
-
actionview (= 4.2.
|
15
|
-
activejob (= 4.2.
|
12
|
+
actionmailer (4.2.3)
|
13
|
+
actionpack (= 4.2.3)
|
14
|
+
actionview (= 4.2.3)
|
15
|
+
activejob (= 4.2.3)
|
16
16
|
mail (~> 2.5, >= 2.5.4)
|
17
17
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
18
|
-
actionpack (4.2.
|
19
|
-
actionview (= 4.2.
|
20
|
-
activesupport (= 4.2.
|
18
|
+
actionpack (4.2.3)
|
19
|
+
actionview (= 4.2.3)
|
20
|
+
activesupport (= 4.2.3)
|
21
21
|
rack (~> 1.6)
|
22
22
|
rack-test (~> 0.6.2)
|
23
23
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
24
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.
|
25
|
-
actionview (4.2.
|
26
|
-
activesupport (= 4.2.
|
24
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
25
|
+
actionview (4.2.3)
|
26
|
+
activesupport (= 4.2.3)
|
27
27
|
builder (~> 3.1)
|
28
28
|
erubis (~> 2.7.0)
|
29
29
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
30
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.
|
31
|
-
activejob (4.2.
|
32
|
-
activesupport (= 4.2.
|
30
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
31
|
+
activejob (4.2.3)
|
32
|
+
activesupport (= 4.2.3)
|
33
33
|
globalid (>= 0.3.0)
|
34
|
-
activemodel (4.2.
|
35
|
-
activesupport (= 4.2.
|
34
|
+
activemodel (4.2.3)
|
35
|
+
activesupport (= 4.2.3)
|
36
36
|
builder (~> 3.1)
|
37
|
-
activerecord (4.2.
|
38
|
-
activemodel (= 4.2.
|
39
|
-
activesupport (= 4.2.
|
37
|
+
activerecord (4.2.3)
|
38
|
+
activemodel (= 4.2.3)
|
39
|
+
activesupport (= 4.2.3)
|
40
40
|
arel (~> 6.0)
|
41
|
-
activesupport (4.2.
|
41
|
+
activesupport (4.2.3)
|
42
42
|
i18n (~> 0.7)
|
43
43
|
json (~> 1.7, >= 1.7.7)
|
44
44
|
minitest (~> 5.1)
|
@@ -62,19 +62,19 @@ GEM
|
|
62
62
|
nokogiri (1.6.6.2)
|
63
63
|
mini_portile (~> 0.6.0)
|
64
64
|
pg (0.18.2)
|
65
|
-
rack (1.6.
|
65
|
+
rack (1.6.4)
|
66
66
|
rack-test (0.6.3)
|
67
67
|
rack (>= 1.0)
|
68
|
-
rails (4.2.
|
69
|
-
actionmailer (= 4.2.
|
70
|
-
actionpack (= 4.2.
|
71
|
-
actionview (= 4.2.
|
72
|
-
activejob (= 4.2.
|
73
|
-
activemodel (= 4.2.
|
74
|
-
activerecord (= 4.2.
|
75
|
-
activesupport (= 4.2.
|
68
|
+
rails (4.2.3)
|
69
|
+
actionmailer (= 4.2.3)
|
70
|
+
actionpack (= 4.2.3)
|
71
|
+
actionview (= 4.2.3)
|
72
|
+
activejob (= 4.2.3)
|
73
|
+
activemodel (= 4.2.3)
|
74
|
+
activerecord (= 4.2.3)
|
75
|
+
activesupport (= 4.2.3)
|
76
76
|
bundler (>= 1.3.0, < 2.0)
|
77
|
-
railties (= 4.2.
|
77
|
+
railties (= 4.2.3)
|
78
78
|
sprockets-rails
|
79
79
|
rails-deprecated_sanitizer (1.0.3)
|
80
80
|
activesupport (>= 4.2.0.alpha)
|
@@ -84,9 +84,9 @@ GEM
|
|
84
84
|
rails-deprecated_sanitizer (>= 1.0.1)
|
85
85
|
rails-html-sanitizer (1.0.2)
|
86
86
|
loofah (~> 2.0)
|
87
|
-
railties (4.2.
|
88
|
-
actionpack (= 4.2.
|
89
|
-
activesupport (= 4.2.
|
87
|
+
railties (4.2.3)
|
88
|
+
actionpack (= 4.2.3)
|
89
|
+
activesupport (= 4.2.3)
|
90
90
|
rake (>= 0.8.7)
|
91
91
|
thor (>= 0.18.1, < 2.0)
|
92
92
|
rake (10.4.2)
|
@@ -101,7 +101,7 @@ GEM
|
|
101
101
|
rspec-mocks (2.99.3)
|
102
102
|
sprockets (3.2.0)
|
103
103
|
rack (~> 1.0)
|
104
|
-
sprockets-rails (2.3.
|
104
|
+
sprockets-rails (2.3.2)
|
105
105
|
actionpack (>= 3.0)
|
106
106
|
activesupport (>= 3.0)
|
107
107
|
sprockets (>= 2.8, < 4.0)
|
@@ -12,30 +12,31 @@ module ActiveRecordPostgresEarthdistance
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def within_box(radius, lat, lng)
|
15
|
-
earth_box = Arel::Nodes::NamedFunction.new('earth_box', [ll_to_earth_coords(lat, lng), quote_value(radius)])
|
16
|
-
where Arel::Nodes::InfixOperation.new('<@', ll_to_earth_columns, earth_box)
|
15
|
+
earth_box = Arel::Nodes::NamedFunction.new('earth_box', [Utils.ll_to_earth_coords(lat, lng), Utils.quote_value(radius)])
|
16
|
+
where Arel::Nodes::InfixOperation.new('<@', Utils.ll_to_earth_columns(self), earth_box)
|
17
17
|
end
|
18
18
|
|
19
19
|
def within_radius(radius, lat, lng)
|
20
|
-
earth_distance = Arel::Nodes::NamedFunction.new('earth_distance', [ll_to_earth_columns, ll_to_earth_coords(lat, lng)])
|
21
|
-
within_box(radius, lat, lng).where(Arel::Nodes::InfixOperation.new('<=', earth_distance, quote_value(radius)))
|
20
|
+
earth_distance = Arel::Nodes::NamedFunction.new('earth_distance', [Utils.ll_to_earth_columns(self), Utils.ll_to_earth_coords(lat, lng)])
|
21
|
+
within_box(radius, lat, lng).where(Arel::Nodes::InfixOperation.new('<=', earth_distance, Utils.quote_value(radius)))
|
22
22
|
end
|
23
23
|
|
24
24
|
def order_by_distance(lat, lng, order = "ASC")
|
25
|
-
earth_distance = Arel::Nodes::NamedFunction.new('earth_distance', [ll_to_earth_columns, ll_to_earth_coords(lat, lng)])
|
25
|
+
earth_distance = Arel::Nodes::NamedFunction.new('earth_distance', [Utils.ll_to_earth_columns(self), Utils.ll_to_earth_coords(lat, lng)])
|
26
26
|
order("#{earth_distance.to_sql} #{order.to_s}")
|
27
27
|
end
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
def ll_to_earth_columns
|
31
|
-
Arel::Nodes::NamedFunction.new('ll_to_earth', [arel_table[
|
30
|
+
module Utils
|
31
|
+
def self.ll_to_earth_columns(klass)
|
32
|
+
Arel::Nodes::NamedFunction.new('ll_to_earth', [klass.arel_table[klass.latitude_column], klass.arel_table[klass.longitude_column]])
|
32
33
|
end
|
33
34
|
|
34
|
-
def ll_to_earth_coords lat, lng
|
35
|
+
def self.ll_to_earth_coords lat, lng
|
35
36
|
Arel::Nodes::NamedFunction.new('ll_to_earth', [quote_value(lat), quote_value(lng)])
|
36
37
|
end
|
37
38
|
|
38
|
-
def quote_value value
|
39
|
+
def self.quote_value value
|
39
40
|
if Arel::Nodes.respond_to?(:build_quoted) # for arel >= 6.0.0
|
40
41
|
Arel::Nodes.build_quoted(value)
|
41
42
|
else
|
@@ -55,6 +56,7 @@ module ActiveRecordPostgresEarthdistance
|
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
59
|
+
|
58
60
|
end
|
59
61
|
|
60
62
|
ActiveRecord::Base.send :include, ActiveRecordPostgresEarthdistance::ActsAsGeolocated
|
@@ -1,6 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "ActiveRecord::Base.act_as_geolocated" do
|
4
|
+
describe 'ActiveRecord::Base' do
|
5
|
+
context "when using .where with a model instance as a placeholder" do
|
6
|
+
let(:place) { Place.create! }
|
7
|
+
subject { Place.where('id = ?', place).first }
|
8
|
+
after { place.destroy! }
|
9
|
+
|
10
|
+
it { should == place }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
4
14
|
describe "#within_box" do
|
5
15
|
let(:test_data) { { lat: nil, lng: nil, radius: nil } }
|
6
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-postgres-earthdistance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diogo Biazus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|