activerecord-postgres-earthdistance 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile.lock +59 -62
- data/README.md +8 -3
- data/activerecord-postgres-earthdistance.gemspec +1 -1
- data/lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb +6 -1
- data/lib/activerecord-postgres-earthdistance/railties.rb +1 -1
- data/spec/act_as_geolocated_spec.rb +27 -0
- metadata +21 -32
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7e87b2bf7fbe3af69b42a9a578f5f3adf8967acd
|
4
|
+
data.tar.gz: ab06b2bdaf4422c238ed5fd3d666c348c1569a4c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a382568c1c7e968ae804c70da525e3e2185c6aa69dd338d5bd57a72e7512367e6f45a7f89d2821d83fbdc26edaba0e698c03961de25aac677a3e92aacdac57a8
|
7
|
+
data.tar.gz: e737a628e1f27075b92e7257cd9186274749f3e551845c3a5a42f7fca7bad0e1e50b25073e974a0177263bb2caaa959b3b7ac5ecdcfa36b48680c9dd3b592812
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
activerecord-postgres-earthdistance (0.
|
4
|
+
activerecord-postgres-earthdistance (0.3.0)
|
5
5
|
pg
|
6
6
|
rails (>= 3.1)
|
7
7
|
rake
|
@@ -9,72 +9,63 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: http://rubygems.org/
|
11
11
|
specs:
|
12
|
-
actionmailer (
|
13
|
-
actionpack (=
|
14
|
-
mail (~> 2.
|
15
|
-
actionpack (
|
16
|
-
|
17
|
-
|
18
|
-
builder (~> 3.0.0)
|
12
|
+
actionmailer (4.0.1)
|
13
|
+
actionpack (= 4.0.1)
|
14
|
+
mail (~> 2.5.4)
|
15
|
+
actionpack (4.0.1)
|
16
|
+
activesupport (= 4.0.1)
|
17
|
+
builder (~> 3.1.0)
|
19
18
|
erubis (~> 2.7.0)
|
20
|
-
|
21
|
-
rack (~>
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
builder (3.0.4)
|
19
|
+
rack (~> 1.5.2)
|
20
|
+
rack-test (~> 0.6.2)
|
21
|
+
activemodel (4.0.1)
|
22
|
+
activesupport (= 4.0.1)
|
23
|
+
builder (~> 3.1.0)
|
24
|
+
activerecord (4.0.1)
|
25
|
+
activemodel (= 4.0.1)
|
26
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
27
|
+
activesupport (= 4.0.1)
|
28
|
+
arel (~> 4.0.0)
|
29
|
+
activerecord-deprecated_finders (1.0.3)
|
30
|
+
activesupport (4.0.1)
|
31
|
+
i18n (~> 0.6, >= 0.6.4)
|
32
|
+
minitest (~> 4.2)
|
33
|
+
multi_json (~> 1.3)
|
34
|
+
thread_safe (~> 0.1)
|
35
|
+
tzinfo (~> 0.3.37)
|
36
|
+
arel (4.0.1)
|
37
|
+
atomic (1.1.14)
|
38
|
+
builder (3.1.4)
|
41
39
|
diff-lcs (1.1.3)
|
42
40
|
erubis (2.7.0)
|
43
|
-
hike (1.2.
|
44
|
-
i18n (0.6.
|
45
|
-
journey (1.0.4)
|
41
|
+
hike (1.2.3)
|
42
|
+
i18n (0.6.5)
|
46
43
|
json (1.7.6)
|
47
|
-
mail (2.
|
48
|
-
i18n (>= 0.4.0)
|
44
|
+
mail (2.5.4)
|
49
45
|
mime-types (~> 1.16)
|
50
46
|
treetop (~> 1.4.8)
|
51
|
-
mime-types (1.
|
52
|
-
|
53
|
-
|
47
|
+
mime-types (1.25.1)
|
48
|
+
minitest (4.7.5)
|
49
|
+
multi_json (1.8.2)
|
50
|
+
pg (0.17.0)
|
54
51
|
polyglot (0.3.3)
|
55
|
-
rack (1.
|
56
|
-
rack-cache (1.2)
|
57
|
-
rack (>= 0.4)
|
58
|
-
rack-ssl (1.3.3)
|
59
|
-
rack
|
52
|
+
rack (1.5.2)
|
60
53
|
rack-test (0.6.2)
|
61
54
|
rack (>= 1.0)
|
62
|
-
rails (
|
63
|
-
actionmailer (=
|
64
|
-
actionpack (=
|
65
|
-
activerecord (=
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
railties (
|
71
|
-
actionpack (=
|
72
|
-
activesupport (=
|
73
|
-
rack-ssl (~> 1.3.2)
|
55
|
+
rails (4.0.1)
|
56
|
+
actionmailer (= 4.0.1)
|
57
|
+
actionpack (= 4.0.1)
|
58
|
+
activerecord (= 4.0.1)
|
59
|
+
activesupport (= 4.0.1)
|
60
|
+
bundler (>= 1.3.0, < 2.0)
|
61
|
+
railties (= 4.0.1)
|
62
|
+
sprockets-rails (~> 2.0.0)
|
63
|
+
railties (4.0.1)
|
64
|
+
actionpack (= 4.0.1)
|
65
|
+
activesupport (= 4.0.1)
|
74
66
|
rake (>= 0.8.7)
|
75
|
-
|
76
|
-
|
77
|
-
rake (10.0.3)
|
67
|
+
thor (>= 0.18.1, < 2.0)
|
68
|
+
rake (10.1.0)
|
78
69
|
rdoc (3.12)
|
79
70
|
json (~> 1.4)
|
80
71
|
rspec (2.12.0)
|
@@ -85,17 +76,23 @@ GEM
|
|
85
76
|
rspec-expectations (2.12.1)
|
86
77
|
diff-lcs (~> 1.1.3)
|
87
78
|
rspec-mocks (2.12.2)
|
88
|
-
sprockets (2.
|
79
|
+
sprockets (2.10.1)
|
89
80
|
hike (~> 1.2)
|
90
81
|
multi_json (~> 1.0)
|
91
82
|
rack (~> 1.0)
|
92
83
|
tilt (~> 1.1, != 1.3.0)
|
93
|
-
|
94
|
-
|
95
|
-
|
84
|
+
sprockets-rails (2.0.1)
|
85
|
+
actionpack (>= 3.0)
|
86
|
+
activesupport (>= 3.0)
|
87
|
+
sprockets (~> 2.8)
|
88
|
+
thor (0.18.1)
|
89
|
+
thread_safe (0.1.3)
|
90
|
+
atomic
|
91
|
+
tilt (1.4.1)
|
92
|
+
treetop (1.4.15)
|
96
93
|
polyglot
|
97
94
|
polyglot (>= 0.3.1)
|
98
|
-
tzinfo (0.3.
|
95
|
+
tzinfo (0.3.38)
|
99
96
|
|
100
97
|
PLATFORMS
|
101
98
|
ruby
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#ActiveRecord + PostgreSQL Earthdistance [![Build Status](https://
|
1
|
+
#ActiveRecord + PostgreSQL Earthdistance [![Build Status](https://travis-ci.org/diogob/activerecord-postgres-earthdistance.png?branch=master)](https://travis-ci.org/diogob/activerecord-postgres-earthdistance)
|
2
2
|
|
3
3
|
Check distances with latitude and longitude using PostgreSQL special indexes.
|
4
4
|
This gem enables your model to query the database using the earthdistance extension. This should be much faster than using trigonometry functions over standart indexs.
|
@@ -47,7 +47,7 @@ Edit the created migration:
|
|
47
47
|
class AddIndexToPlaces < ActiveRecord::Migration
|
48
48
|
def change
|
49
49
|
add_earthdistance_index :places
|
50
|
-
end
|
50
|
+
end
|
51
51
|
end
|
52
52
|
```
|
53
53
|
|
@@ -89,6 +89,11 @@ To query for all places within a given radius of 100 meters from the origin 30,5
|
|
89
89
|
Place.within_radius(500, 30, 50).all
|
90
90
|
```
|
91
91
|
|
92
|
+
You can also order the records based on the distance from a point
|
93
|
+
```ruby
|
94
|
+
Place.within_radius(500, 30, 50).order_by_distance(20,30)
|
95
|
+
```
|
96
|
+
|
92
97
|
##Test Database
|
93
98
|
|
94
99
|
To have earthdistance enabled when you load your database schema (as happens in rake db:test:prepare), you
|
@@ -108,7 +113,7 @@ unsure about the implications of this change, we suggest reading this
|
|
108
113
|
##Help
|
109
114
|
|
110
115
|
You can use issues in github for that. Or else you can reach us at
|
111
|
-
twitter: [@dbiazus](https://twitter.com/#!/dbiazus)
|
116
|
+
twitter: [@dbiazus](https://twitter.com/#!/dbiazus)
|
112
117
|
|
113
118
|
##Note on Patches/Pull Requests
|
114
119
|
|
@@ -14,9 +14,14 @@ module ActiveRecordPostgresEarthdistance
|
|
14
14
|
|
15
15
|
def within_radius radius, lat, lng
|
16
16
|
where(["ll_to_earth(#{self.latitude_column}, #{self.longitude_column}) <@ earth_box(ll_to_earth(?, ?), ?)" +
|
17
|
-
"AND earth_distance(ll_to_earth(#{self.latitude_column}, #{self.longitude_column}), ll_to_earth(?, ?)) <= ?",
|
17
|
+
"AND earth_distance(ll_to_earth(#{self.latitude_column}, #{self.longitude_column}), ll_to_earth(?, ?)) <= ?",
|
18
18
|
lat, lng, radius, lat, lng, radius])
|
19
19
|
end
|
20
|
+
|
21
|
+
def order_by_distance lat, lng, order: "ASC"
|
22
|
+
order("earth_distance(ll_to_earth(#{self.latitude_column}, #{self.longitude_column}), ll_to_earth(#{lat}, #{lng})) #{order}")
|
23
|
+
end
|
24
|
+
|
20
25
|
end
|
21
26
|
end
|
22
27
|
end
|
@@ -20,7 +20,7 @@ class EarthDistance < Rails::Railtie
|
|
20
20
|
include Rails::Generators::Migration
|
21
21
|
|
22
22
|
def self.source_root
|
23
|
-
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
23
|
+
@source_root ||= File.join(File.dirname(__FILE__), '..', 'templates')
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.next_migration_number(dirname)
|
@@ -8,6 +8,10 @@ describe "ActiveRecord::Base.act_as_geolocated" do
|
|
8
8
|
@place = Place.create!(:lat => -30.0277041, :lng => -51.2287346)
|
9
9
|
end
|
10
10
|
|
11
|
+
after(:all) do
|
12
|
+
@place.destroy
|
13
|
+
end
|
14
|
+
|
11
15
|
context "when query with null data" do
|
12
16
|
it{ should == [] }
|
13
17
|
end
|
@@ -26,4 +30,27 @@ describe "ActiveRecord::Base.act_as_geolocated" do
|
|
26
30
|
let(:test_data){ {radius: 1000, lat: -27.5969039, lng: -48.5494544} }
|
27
31
|
end
|
28
32
|
end
|
33
|
+
|
34
|
+
describe "#order_by_distance" do
|
35
|
+
let(:current_location){ {lat: nil, lng: nil, radius: nil} }
|
36
|
+
subject{ Place.order_by_distance(current_location[:lat], current_location[:lng]) }
|
37
|
+
before(:all) do
|
38
|
+
@place_1 = Place.create!(:lat => 52.370216, :lng => 4.895168) #Amsterdam
|
39
|
+
@place_2 = Place.create!(:lat => 52.520007, :lng => 13.404954) #Berlin
|
40
|
+
end
|
41
|
+
after(:all) do
|
42
|
+
@place_1.destroy
|
43
|
+
@place_2.destroy
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when sorting on distance" do
|
47
|
+
let(:current_location){{lat: 51.511214, lng: 0.119824}} #London
|
48
|
+
it{ should == [@place_1, @place_2] }
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when sorting on distance from another location" do
|
52
|
+
let(:current_location){{lat: 52.229676, lng: 21.012229}} #Warsaw
|
53
|
+
it{ should == [@place_2, @place_1] }
|
54
|
+
end
|
55
|
+
end
|
29
56
|
end
|
metadata
CHANGED
@@ -1,100 +1,88 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-postgres-earthdistance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Diogo Biazus
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-11-28 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rails
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '3.1'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '3.1'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: pg
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: bundler
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: rdoc
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: rspec
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
87
|
- - ~>
|
100
88
|
- !ruby/object:Gem::Version
|
@@ -102,7 +90,6 @@ dependencies:
|
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
94
|
- - ~>
|
108
95
|
- !ruby/object:Gem::Version
|
@@ -138,26 +125,28 @@ files:
|
|
138
125
|
homepage: http://github.com/diogob/activerecord-postgres-earthdistance
|
139
126
|
licenses:
|
140
127
|
- MIT
|
128
|
+
metadata: {}
|
141
129
|
post_install_message:
|
142
130
|
rdoc_options: []
|
143
131
|
require_paths:
|
144
132
|
- lib
|
145
133
|
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
-
none: false
|
147
134
|
requirements:
|
148
|
-
- -
|
135
|
+
- - '>='
|
149
136
|
- !ruby/object:Gem::Version
|
150
137
|
version: 1.8.7
|
151
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
-
none: false
|
153
139
|
requirements:
|
154
|
-
- -
|
140
|
+
- - '>='
|
155
141
|
- !ruby/object:Gem::Version
|
156
142
|
version: 1.3.6
|
157
143
|
requirements: []
|
158
144
|
rubyforge_project:
|
159
|
-
rubygems_version:
|
145
|
+
rubygems_version: 2.0.7
|
160
146
|
signing_key:
|
161
|
-
specification_version:
|
147
|
+
specification_version: 4
|
162
148
|
summary: Check distances with latitude and longitude using PostgreSQL special indexes
|
163
|
-
test_files:
|
149
|
+
test_files:
|
150
|
+
- spec/act_as_geolocated_spec.rb
|
151
|
+
- spec/fixtures/place.rb
|
152
|
+
- spec/spec_helper.rb
|