mongoid_geospatial 2.7.2 → 2.8.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ac73953bb1d3c6852d3cef4a15f7e14329742be3
4
+ data.tar.gz: 2ab0b1b7b534817cc8627ea154057bc436c8304e
5
+ SHA512:
6
+ metadata.gz: d1927bdc7f587f7b504d9a59d9b7a698391f87582e025f8df00e0672921ba93b060b8208cda3619d1f6df2bccf8300d0d86f91c9996b86da485f3ee39778b7c9
7
+ data.tar.gz: e8357faab54e5f8f1d09c8dbe5fc922d9c05bf469d4132c0ffe2c21f43eae93c21b4e3aa9528bd02f8ce917ded0c3a2337f48ff951c497d1aef27a9221be2b1f
@@ -17,7 +17,7 @@ module Mongoid
17
17
 
18
18
  def center_point
19
19
  min, max = *bbox
20
- [min[0] + max[0] / 2.0, min[1] + max[1] / 2.0]
20
+ [(min[0] + max[0]) / 2.0, (min[1] + max[1]) / 2.0]
21
21
  end
22
22
  alias :center :center_point
23
23
 
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Geospatial
3
- VERSION = "2.7.2"
3
+ VERSION = "2.8.0"
4
4
  end
5
5
  end
@@ -5,7 +5,6 @@ module Mongoid
5
5
  module Geospatial
6
6
 
7
7
  class Point
8
-
9
8
  def to_geo
10
9
  RGeo::Geographic.spherical_factory.point x, y
11
10
  end
@@ -25,23 +24,27 @@ module Mongoid
25
24
  end
26
25
  end
27
26
 
27
+ class GeometryField
28
+ private
29
+ def points
30
+ self.map do |pair|
31
+ RGeo::Geographic.spherical_factory.point(*pair)
32
+ end
33
+ end
34
+ end
28
35
 
29
36
  class Line < GeometryField
30
37
  def to_geo
31
- RGeo::Geographic.spherical_factory.line_string self
38
+ RGeo::Geographic.spherical_factory.line_string points
32
39
  end
33
40
 
34
41
  end
35
42
 
36
43
  class Polygon < GeometryField
37
44
  def to_geo
38
- points = self.map do |pair|
39
- RGeo::Geographic.spherical_factory.point *pair
40
- end
41
45
  ring = RGeo::Geographic.spherical_factory.linear_ring points
42
46
  RGeo::Geographic.spherical_factory.polygon ring
43
47
  end
44
-
45
48
  end
46
49
  end
47
50
  end
@@ -21,4 +21,5 @@ Gem::Specification.new do |gem|
21
21
  gem.add_development_dependency('rspec', ['>= 2.11'])
22
22
  gem.add_development_dependency('kaminari', ['>= 0'])
23
23
  gem.add_development_dependency('will_paginate', ['>= 0'])
24
+ gem.add_development_dependency("rake")
24
25
  end
@@ -22,12 +22,12 @@ describe Mongoid::Geospatial::Line do
22
22
 
23
23
  it "should have a center point" do
24
24
  geom = Mongoid::Geospatial::Line.new [[1,1],[1,1],[9,9],[9,9]]
25
- geom.center.should eq([5.5,5.5])
25
+ geom.center.should eq([5.0,5.0])
26
26
  end
27
27
 
28
28
  it "should have a radius helper" do
29
29
  geom = Mongoid::Geospatial::Line.new [[1,1],[1,1],[9,9],[9,9]]
30
- geom.radius(10).should eq([[5.5,5.5], 10])
30
+ geom.radius(10).should eq([[5.0,5.0], 10])
31
31
  end
32
32
 
33
33
  it "should have a radius sphere" do
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Geospatial::Point do
4
4
 
5
- it "should not inferfer with mongoid" do
5
+ it "should not interfer with mongoid" do
6
6
  Bar.create!(name: "Moe's")
7
7
  Bar.count.should eql(1)
8
8
  end
@@ -22,12 +22,12 @@ describe Mongoid::Geospatial::Polygon do
22
22
 
23
23
  it "should have a center point" do
24
24
  geom = Mongoid::Geospatial::Polygon.new [[1,1],[1,1],[9,9],[9,9]]
25
- geom.center.should eq([5.5,5.5])
25
+ geom.center.should eq([5.0,5.0])
26
26
  end
27
27
 
28
28
  it "should have a radius helper" do
29
29
  geom = Mongoid::Geospatial::Polygon.new [[1,1],[1,1],[9,9],[9,9]]
30
- geom.radius(10).should eq([[5.5,5.5], 10])
30
+ geom.radius(10).should eq([[5.0,5.0], 10])
31
31
  end
32
32
 
33
33
  it "should have a radius sphere" do
@@ -8,7 +8,7 @@ describe Mongoid::Fields do
8
8
  end
9
9
 
10
10
  it "should created indexes" do
11
- Bar.index_options.keys.should include({'location' => '2d'})
11
+ Bar.index_options.keys.should include({:location => '2d'})
12
12
  end
13
13
 
14
14
  it "should set spatial fields" do
@@ -10,7 +10,7 @@ describe Mongoid::Geospatial::Point do
10
10
  load "#{File.dirname(__FILE__)}/../../models/place.rb"
11
11
  end
12
12
 
13
- it "should not inferfer with mongoid" do
13
+ it "should not interfer with mongoid" do
14
14
  Place.create!(name: "Moe's")
15
15
  Place.count.should eql(1)
16
16
  end
@@ -1,61 +1,119 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Mongoid::Geospatial::Point do
3
+ describe "RGeo Wrapper" do
4
4
 
5
5
  before(:all) do
6
6
  Mongoid::Geospatial.send(:remove_const, 'Point')
7
+ Mongoid::Geospatial.send(:remove_const, 'Polygon')
8
+ Mongoid::Geospatial.send(:remove_const, 'Line')
9
+
7
10
  load "#{File.dirname(__FILE__)}/../../../lib/mongoid_geospatial/fields/point.rb"
11
+ load "#{File.dirname(__FILE__)}/../../../lib/mongoid_geospatial/fields/polygon.rb"
12
+ load "#{File.dirname(__FILE__)}/../../../lib/mongoid_geospatial/fields/line.rb"
13
+
8
14
  Object.send(:remove_const, 'Bar')
9
15
  load "#{File.dirname(__FILE__)}/../../models/bar.rb"
16
+
17
+ Object.send(:remove_const, 'Farm')
18
+ load "#{File.dirname(__FILE__)}/../../models/farm.rb"
19
+
20
+ Object.send(:remove_const, 'River')
21
+ load "#{File.dirname(__FILE__)}/../../models/river.rb"
10
22
  end
11
23
 
12
- it "should not inferfer with mongoid" do
13
- Bar.create!(name: "Moe's")
14
- Bar.count.should eql(1)
24
+ describe Mongoid::Geospatial::Point do
25
+ it "should not interfer with mongoid" do
26
+ Bar.create!(name: "Moe's")
27
+ Bar.count.should eql(1)
28
+ end
29
+
30
+ it "should not respond to distance before loading external" do
31
+ bar = Bar.create!(location: [5,5])
32
+ bar.location.should_not respond_to(:distance)
33
+ end
15
34
  end
16
35
 
17
- it "should not respond to distance before loading external" do
18
- bar = Bar.create!(location: [5,5])
19
- bar.location.should_not respond_to(:distance)
36
+ describe Mongoid::Geospatial::Polygon do
37
+ it "should not interfer with mongoid" do
38
+ Farm.create!(name: "Springfield Nuclear Power Plant")
39
+ Farm.count.should eql(1)
40
+ end
41
+
42
+ it "should not respond to to_geo before loading external" do
43
+ farm = Farm.create!(area: [[5,5],[6,5],[6,6],[5,6]])
44
+ farm.area.should_not respond_to(:to_geo)
45
+ end
20
46
  end
21
47
 
48
+ describe Mongoid::Geospatial::Line do
49
+ it "should not interfer with mongoid" do
50
+ River.create!(name: "Mississippi")
51
+ River.count.should eql(1)
52
+ end
53
+
54
+ it "should not respond to to_geo before loading external" do
55
+ river = River.create!(source: [[5,5],[6,5],[6,6],[5,6]])
56
+ river.source.should_not respond_to(:to_geo)
57
+ end
58
+ end
22
59
 
23
60
  describe "queryable" do
24
61
 
25
62
  before do
26
63
  Mongoid::Geospatial.use_rgeo
27
64
  Bar.create_indexes
65
+ Farm.create_indexes
66
+ River.create_indexes
28
67
  end
29
68
 
30
69
  describe "(de)mongoize" do
31
70
 
32
- it "should mongoize array" do
33
- geom = Bar.new(location: [10, -9]).location
34
- geom.class.should eql(Mongoid::Geospatial::Point)
35
- geom.to_geo.class.should eql(RGeo::Geographic::SphericalPointImpl)
36
- geom.x.should be_within(0.1).of(10)
37
- geom.to_geo.y.should be_within(0.1).of(-9)
38
- end
71
+ describe Mongoid::Geospatial::Point do
72
+ it "should mongoize array" do
73
+ geom = Bar.new(location: [10, -9]).location
74
+ geom.class.should eql(Mongoid::Geospatial::Point)
75
+ geom.to_geo.class.should eql(RGeo::Geographic::SphericalPointImpl)
76
+ geom.x.should be_within(0.1).of(10)
77
+ geom.to_geo.y.should be_within(0.1).of(-9)
78
+ end
39
79
 
40
- it "should mongoize hash" do
41
- geom = Bar.new(location: {x: 10, y: -9}).location
42
- geom.class.should eql(Mongoid::Geospatial::Point)
43
- geom.to_geo.class.should eql(RGeo::Geographic::SphericalPointImpl)
44
- end
80
+ it "should mongoize hash" do
81
+ geom = Bar.new(location: {x: 10, y: -9}).location
82
+ geom.class.should eql(Mongoid::Geospatial::Point)
83
+ geom.to_geo.class.should eql(RGeo::Geographic::SphericalPointImpl)
84
+ end
45
85
 
46
- it "should accept an RGeo object" do
47
- point = RGeo::Geographic.spherical_factory.point 1, 2
48
- bar = Bar.create!(location: point)
49
- bar.location.x.should be_within(0.1).of(1)
50
- bar.location.y.should be_within(0.1).of(2)
86
+ it "should accept an RGeo object" do
87
+ point = RGeo::Geographic.spherical_factory.point 1, 2
88
+ bar = Bar.create!(location: point)
89
+ bar.location.x.should be_within(0.1).of(1)
90
+ bar.location.y.should be_within(0.1).of(2)
91
+ end
92
+
93
+ it "should calculate 3d distances by default" do
94
+ bar = Bar.create! location: [-73.77694444, 40.63861111 ]
95
+ bar2 = Bar.create! location: [-118.40, 33.94] #,:unit=>:mi, :spherical => true)
96
+ bar.location.distance(bar2.location).to_i.should be_within(1).of(3978262)
97
+ end
51
98
  end
52
99
 
53
- it "should calculate 3d distances by default" do
54
- bar = Bar.create! location: [-73.77694444, 40.63861111 ]
55
- bar2 = Bar.create! location: [-118.40, 33.94] #,:unit=>:mi, :spherical => true)
56
- bar.location.distance(bar2.location).to_i.should be_within(1).of(3978262)
100
+ describe Mongoid::Geospatial::Polygon do
101
+ it "should mongoize array" do
102
+ geom = Farm.create!(area: [[5,5],[6,5],[6,6],[5,6]]).area
103
+ geom.class.should eql(Mongoid::Geospatial::Polygon)
104
+ geom.to_geo.class.should eql(RGeo::Geographic::SphericalPolygonImpl)
105
+ geom.to_geo.to_s.should eq "POLYGON ((5.0 5.0, 6.0 5.0, 6.0 6.0, 5.0 6.0, 5.0 5.0))"
106
+ end
57
107
  end
58
108
 
109
+ describe Mongoid::Geospatial::Line do
110
+ it "should mongoize array" do
111
+ geom = River.create!(source: [[5,5],[6,5],[6,6],[5,6]]).source
112
+ geom.class.should eql(Mongoid::Geospatial::Line)
113
+ geom.to_geo.class.should eql(RGeo::Geographic::SphericalLineStringImpl)
114
+ geom.to_geo.to_s.should eq "LINESTRING (5.0 5.0, 6.0 5.0, 6.0 6.0, 5.0 6.0)"
115
+ end
116
+ end
59
117
  end
60
118
  end
61
119
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_geospatial
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.2
5
- prerelease:
4
+ version: 2.8.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ryan Ong
@@ -10,102 +9,104 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-03-02 00:00:00.000000000 Z
12
+ date: 2013-07-21 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: mongoid
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: 3.0.0
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - '>='
29
26
  - !ruby/object:Gem::Version
30
27
  version: 3.0.0
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: activesupport
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - '>='
37
33
  - !ruby/object:Gem::Version
38
34
  version: '3.2'
39
35
  type: :runtime
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
39
+ - - '>='
45
40
  - !ruby/object:Gem::Version
46
41
  version: '3.2'
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: yard
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - ! '>='
46
+ - - '>='
53
47
  - !ruby/object:Gem::Version
54
48
  version: 0.6.0
55
49
  type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
- - - ! '>='
53
+ - - '>='
61
54
  - !ruby/object:Gem::Version
62
55
  version: 0.6.0
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: rspec
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
- - - ! '>='
60
+ - - '>='
69
61
  - !ruby/object:Gem::Version
70
62
  version: '2.11'
71
63
  type: :development
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
- - - ! '>='
67
+ - - '>='
77
68
  - !ruby/object:Gem::Version
78
69
  version: '2.11'
79
70
  - !ruby/object:Gem::Dependency
80
71
  name: kaminari
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
- - - ! '>='
74
+ - - '>='
85
75
  - !ruby/object:Gem::Version
86
76
  version: '0'
87
77
  type: :development
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
- - - ! '>='
81
+ - - '>='
93
82
  - !ruby/object:Gem::Version
94
83
  version: '0'
95
84
  - !ruby/object:Gem::Dependency
96
85
  name: will_paginate
97
86
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
87
  requirements:
100
- - - ! '>='
88
+ - - '>='
101
89
  - !ruby/object:Gem::Version
102
90
  version: '0'
103
91
  type: :development
104
92
  prerelease: false
105
93
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
94
  requirements:
108
- - - ! '>='
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rake
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
109
110
  - !ruby/object:Gem::Version
110
111
  version: '0'
111
112
  description: Mongoid Extension that simplifies spatial calculations. Adds integration
@@ -167,27 +168,26 @@ files:
167
168
  - spec/support/mongoid.yml
168
169
  homepage: https://github.com/nofxx/mongoid_geospatial
169
170
  licenses: []
171
+ metadata: {}
170
172
  post_install_message:
171
173
  rdoc_options: []
172
174
  require_paths:
173
175
  - lib
174
176
  required_ruby_version: !ruby/object:Gem::Requirement
175
- none: false
176
177
  requirements:
177
- - - ! '>='
178
+ - - '>='
178
179
  - !ruby/object:Gem::Version
179
180
  version: '0'
180
181
  required_rubygems_version: !ruby/object:Gem::Requirement
181
- none: false
182
182
  requirements:
183
- - - ! '>='
183
+ - - '>='
184
184
  - !ruby/object:Gem::Version
185
185
  version: '0'
186
186
  requirements: []
187
187
  rubyforge_project:
188
- rubygems_version: 1.8.23
188
+ rubygems_version: 2.0.3
189
189
  signing_key:
190
- specification_version: 3
190
+ specification_version: 4
191
191
  summary: Mongoid Extension that simplifies and adds support for MongoDB Geo Spatial
192
192
  Calculations.
193
193
  test_files: