mongoid-geospatial 7.0.0 → 7.2.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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +109 -33
  3. data/lib/mongoid/geospatial/config/point.rb +5 -2
  4. data/lib/mongoid/geospatial/config.rb +2 -0
  5. data/lib/mongoid/geospatial/ext/rgeo_spherical_point_impl.rb +2 -0
  6. data/lib/mongoid/geospatial/fields/box.rb +2 -0
  7. data/lib/mongoid/geospatial/fields/circle.rb +2 -2
  8. data/lib/mongoid/geospatial/fields/line_string.rb +2 -0
  9. data/lib/mongoid/geospatial/fields/point.rb +59 -50
  10. data/lib/mongoid/geospatial/fields/polygon.rb +2 -0
  11. data/lib/mongoid/geospatial/geometry_field.rb +4 -2
  12. data/lib/mongoid/geospatial/helpers/delegate.rb +2 -0
  13. data/lib/mongoid/geospatial/helpers/geom.rb +22 -0
  14. data/lib/mongoid/geospatial/helpers/spatial.rb +2 -0
  15. data/lib/mongoid/geospatial/helpers/sphere.rb +2 -0
  16. data/lib/mongoid/geospatial/keys.rb +20 -0
  17. data/lib/mongoid/geospatial/version.rb +3 -1
  18. data/lib/mongoid/geospatial/wrappers/georuby.rb +2 -0
  19. data/lib/mongoid/geospatial/wrappers/rgeo.rb +2 -0
  20. data/lib/mongoid/geospatial.rb +196 -16
  21. metadata +7 -75
  22. data/.coveralls.yml +0 -1
  23. data/.gitignore +0 -49
  24. data/.hound.yml +0 -2
  25. data/.rspec +0 -3
  26. data/.rubocop.yml +0 -8
  27. data/.travis.yml +0 -33
  28. data/CHANGELOG.md +0 -23
  29. data/CONTRIBUTING.md +0 -118
  30. data/Gemfile +0 -17
  31. data/Guardfile +0 -16
  32. data/RELEASING.md +0 -62
  33. data/Rakefile +0 -20
  34. data/mongoid-geospatial.gemspec +0 -18
  35. data/spec/bench +0 -64
  36. data/spec/models/address.rb +0 -69
  37. data/spec/models/alarm.rb +0 -12
  38. data/spec/models/bar.rb +0 -14
  39. data/spec/models/bus.rb +0 -12
  40. data/spec/models/event.rb +0 -18
  41. data/spec/models/farm.rb +0 -13
  42. data/spec/models/person.rb +0 -91
  43. data/spec/models/phone.rb +0 -8
  44. data/spec/models/place.rb +0 -13
  45. data/spec/models/river.rb +0 -22
  46. data/spec/mongoid/geospatial/config_spec.rb +0 -22
  47. data/spec/mongoid/geospatial/fields/box_spec.rb +0 -8
  48. data/spec/mongoid/geospatial/fields/circle_spec.rb +0 -8
  49. data/spec/mongoid/geospatial/fields/line_string_spec.rb +0 -78
  50. data/spec/mongoid/geospatial/fields/point_spec.rb +0 -296
  51. data/spec/mongoid/geospatial/fields/polygon_spec.rb +0 -87
  52. data/spec/mongoid/geospatial/geospatial_spec.rb +0 -222
  53. data/spec/mongoid/geospatial/helpers/core_spec.rb +0 -35
  54. data/spec/mongoid/geospatial/helpers/delegate_spec.rb +0 -67
  55. data/spec/mongoid/geospatial/helpers/spatial_spec.rb +0 -40
  56. data/spec/mongoid/geospatial/helpers/sphere_spec.rb +0 -31
  57. data/spec/mongoid/geospatial/wrappers/georuby_spec.rb +0 -63
  58. data/spec/mongoid/geospatial/wrappers/rgeo_spec.rb +0 -115
  59. data/spec/mongoid.yml +0 -298
  60. data/spec/spec_helper.rb +0 -42
  61. data/spec/support/authentication.rb +0 -28
  62. data/spec/support/mongod.conf +0 -3
  63. data/spec/support/mongoid.yml +0 -19
data/RELEASING.md DELETED
@@ -1,62 +0,0 @@
1
- Releasing Mongoid::Geospatial
2
- =============================
3
-
4
- There're no particular rules about when to release mongoid-geospatial. Release bug fixes frequently, features not so frequently and breaking API changes rarely.
5
-
6
- ### Release
7
-
8
- Run tests, check that all tests succeed locally.
9
-
10
- ```
11
- bundle install
12
- bundle exec rake
13
- ```
14
-
15
- Check that the last build succeeded in [Travis CI](https://travis-ci.org/mongoid/mongoid-geospatial) for all supported platforms.
16
-
17
- Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.
18
-
19
- ```
20
- ### 0.4.0 (2014-01-27)
21
- ```
22
-
23
- Remove the line with "Your contribution here.", since there will be no more contributions to this release.
24
-
25
- Commit your changes.
26
-
27
- ```
28
- git add CHANGELOG.md lib/mongoid/geospatial/version.rb
29
- git commit -m "Preparing for release, 0.4.0."
30
- git push origin master
31
- ```
32
-
33
- Release.
34
-
35
- ```
36
- $ rake release
37
-
38
- mongoid-geospatial 0.4.0 built to pkg/mongoid-geospatial-0.4.0.gem.
39
- Tagged v0.4.0.
40
- Pushed git commits and tags.
41
- Pushed mongoid-geospatial 0.4.0 to rubygems.org.
42
- ```
43
-
44
- ### Prepare for the Next Version
45
-
46
- Add the next release to [CHANGELOG.md](CHANGELOG.md).
47
-
48
- ```
49
- ### 0.4.1 (Next)
50
-
51
- * Your contribution here.
52
- ```
53
-
54
- Increment the minor version, modify [lib/mongoid/geospatial/version.rb](lib/mongoid/geospatial/version.rb).
55
-
56
- Commit your changes.
57
-
58
- ```
59
- git add CHANGELOG.md lib/mongoid/geospatial/version.rb
60
- git commit -m "Preparing for next developer iteration, 0.4.1."
61
- git push origin master
62
- ```
data/Rakefile DELETED
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env rake
2
- require 'bundler/gem_tasks'
3
-
4
- require 'rspec/core'
5
- require 'rspec/core/rake_task'
6
- RSpec::Core::RakeTask.new(:spec) do |spec|
7
- spec.pattern = FileList['spec/**/*_spec.rb']
8
- end
9
-
10
- RSpec::Core::RakeTask.new(:rcov) do |spec|
11
- spec.pattern = 'spec/**/*_spec.rb'
12
- spec.rcov = true
13
- end
14
-
15
- require 'rubocop/rake_task'
16
- RuboCop::RakeTask.new(:rubocop)
17
-
18
- task default: %i[rubocop spec]
19
-
20
- require 'yard'
@@ -1,18 +0,0 @@
1
- require File.expand_path('lib/mongoid/geospatial/version', __dir__)
2
-
3
- Gem::Specification.new do |gem|
4
- gem.authors = ['Ryan Ong', 'Marcos Piccinini']
5
- gem.email = ['use@git.hub.com']
6
- gem.summary = 'Mongoid Extension that simplifies MongoDB Geospatial Operations.'
7
- gem.description = 'Mongoid Extension that simplifies MongoDB casting and operations on spatial Ruby objects.'
8
- gem.homepage = 'https://github.com/mongoid/mongoid-geospatial'
9
-
10
- gem.files = `git ls-files`.split("\n")
11
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
12
- gem.name = 'mongoid-geospatial'
13
- gem.require_paths = ['lib']
14
- gem.version = Mongoid::Geospatial::VERSION
15
- gem.license = 'MIT'
16
-
17
- gem.add_dependency('mongoid', ['>= 4.0.0'])
18
- end
data/spec/bench DELETED
@@ -1,64 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Just for fun
4
- #
5
- $LOAD_PATH << File.expand_path('../lib', __dir__)
6
-
7
- require 'mongoid/geospatial'
8
-
9
- Mongoid.configure do |config|
10
- config.connect_to('mongoid_geospatial_bench')
11
- end
12
-
13
- Mongoid::Geospatial.with_georuby!
14
- Mongoid::Geospatial.with_rgeo!
15
-
16
- class NoGeo
17
- include Mongoid::Document
18
- field :name
19
- end
20
-
21
- class Rider
22
- include Mongoid::Document
23
- include Mongoid::Geospatial
24
- field :name
25
- end
26
-
27
- class Cafe
28
- include Mongoid::Document
29
- include Mongoid::Geospatial
30
- field :name
31
- field :spot, type: Point
32
- end
33
-
34
- Mongoid.purge!
35
- # [NoGeo, Rider, Cafe].each(&:delete_all)
36
-
37
- Benchmark.bmbm do |b|
38
- [100, 1000, 3000].each do |t|
39
- nogeo = []
40
- cafes = []
41
- b.report("#{t} W NoGeo") do
42
- t.times { nogeo << NoGeo.create(name: 'Boring').id }
43
- end
44
- b.report("#{t} W Rider") { t.times { Rider.create(name: 'Munro') } }
45
-
46
- b.report("#{t} W Cafe ") do
47
- t.times { cafes << Cafe.create(name: 'Bacco', spot: [3, 3]).id }
48
- end
49
- # puts "---"
50
- b.report("#{t} R NoGeo") { nogeo.each { |id| NoGeo.find(id) } }
51
- # b.report("#{t} R Rider") { t.times { Rider.create(name: 'Munro') } }
52
- b.report("#{t} R Cafe ") { cafes.each { |id| Cafe.find(id) } }
53
- b.report("#{t} R Cafe Georuby") { cafes.each { |id| Cafe.find(id).spot.to_geo } }
54
- b.report("#{t} R Cafe RGeo") { cafes.each { |id| Cafe.find(id).spot.to_rgeo } }
55
- end
56
- b.report('R Cafe GeoRuby') do
57
- cafe = Cafe.first
58
- 1_000_000.times { cafe.spot.to_geo }
59
- end
60
- b.report('R Cafe RGeo') do
61
- cafe = Cafe.first
62
- 1_000_000.times { cafe.spot.to_rgeo }
63
- end
64
- end
@@ -1,69 +0,0 @@
1
- # Sample spec class
2
- class Address
3
- include Mongoid::Document
4
-
5
- field :_id, type: String, default: -> { street.try(:parameterize) }
6
-
7
- attr_accessor :mode
8
-
9
- field :address_type
10
- field :number, type: Integer
11
- field :street
12
- field :city
13
- field :state
14
- field :post_code
15
- field :parent_title
16
- field :services, type: Array
17
- field :latlng, type: Array
18
- field :map, type: Hash
19
-
20
- embeds_many :locations, validate: false
21
- embeds_one :code, validate: false
22
- embeds_one :target, as: :targetable, validate: false
23
-
24
- embedded_in :addressable, polymorphic: true do
25
- def extension
26
- 'Testing'
27
- end
28
-
29
- def doctor?
30
- title == 'Dr'
31
- end
32
- end
33
-
34
- accepts_nested_attributes_for :locations, :code, :target
35
-
36
- belongs_to :account
37
-
38
- scope :without_postcode, where(postcode: nil)
39
- scope :rodeo, where(street: 'Rodeo Dr') do
40
- def mansion?
41
- all? { |address| address.street == 'Rodeo Dr' }
42
- end
43
- end
44
-
45
- validates_presence_of :street, on: :update
46
- validates_format_of :street, with: /\D/, allow_nil: true
47
-
48
- def set_parent=(set = false)
49
- self.parent_title = addressable.title if set
50
- end
51
-
52
- def <=>(other)
53
- street <=> other.street
54
- end
55
-
56
- class << self
57
- def california
58
- where(state: 'CA')
59
- end
60
-
61
- def homes
62
- where(address_type: 'Home')
63
- end
64
-
65
- def streets
66
- all.map(&:street)
67
- end
68
- end
69
- end
data/spec/models/alarm.rb DELETED
@@ -1,12 +0,0 @@
1
- # Sample spec class
2
- class Alarm
3
- include Mongoid::Document
4
- include Mongoid::Geospatial
5
-
6
- field :name
7
- field :radius, type: Circle
8
- field :area, type: Box
9
- field :spot, type: Point, sphere: true
10
-
11
- spatial_scope :spot
12
- end
data/spec/models/bar.rb DELETED
@@ -1,14 +0,0 @@
1
- # Sample spec class
2
- class Bar
3
- include Mongoid::Document
4
- include Mongoid::Geospatial
5
-
6
- field :name, type: String
7
-
8
- field :location, type: Point, spatial: true
9
-
10
- has_one :rating, as: :ratable
11
-
12
- spherical_index :location
13
- spatial_scope :location
14
- end
data/spec/models/bus.rb DELETED
@@ -1,12 +0,0 @@
1
- # Sample spec class
2
- class Bus
3
- include Mongoid::Document
4
- include Mongoid::Geospatial
5
-
6
- field :name
7
- field :plates, type: String
8
- field :location, type: Point, delegate: true
9
-
10
- spatial_index :location
11
- spatial_scope :location
12
- end
data/spec/models/event.rb DELETED
@@ -1,18 +0,0 @@
1
- # Sample spec class
2
- class Event
3
- include Mongoid::Document
4
- include Mongoid::Geospatial
5
-
6
- field :name
7
- field :date, type: Date
8
-
9
- field :location, type: Point, delegate: true, default: [7, 7]
10
-
11
- def self.each_day(start_date, end_date)
12
- groups = only(:date).asc(:date)
13
- .where(:date.gte => start_date, :date.lte => end_date).group
14
- groups.each do |hash|
15
- yield(hash['date'], hash['group'])
16
- end
17
- end
18
- end
data/spec/models/farm.rb DELETED
@@ -1,13 +0,0 @@
1
- # Sample spec class
2
- class Farm
3
- include Mongoid::Document
4
- include Mongoid::Geospatial
5
-
6
- field :name, type: String
7
- field :geom, type: Point, sphere: true
8
- field :area, type: Polygon, spatial: true
9
- field :m2, type: Integer
10
-
11
- spatial_index :geom
12
- spatial_index :area
13
- end
@@ -1,91 +0,0 @@
1
- # Sample spec class
2
- class Person
3
- include Mongoid::Document
4
- include Mongoid::Timestamps
5
- # include Mongoid::Versioning
6
- include Mongoid::Geospatial
7
-
8
- attr_accessor :mode
9
-
10
- class_attribute :somebody_elses_important_class_options
11
- self.somebody_elses_important_class_options = { keep_me_around: true }
12
-
13
- field :ssn
14
- field :title
15
- field :terms, type: Boolean
16
- field :pets, type: Boolean, default: false
17
- field :age, type: Integer, default: 100
18
- field :dob, type: Date
19
- field :lunch_time, type: Time
20
- field :aliases, type: Array
21
- field :map, type: Hash
22
- field :score, type: Integer
23
- field :owner_id, type: Integer
24
- field :reading, type: Object
25
- # field :bson_id, type: bson_object_id_class
26
- field :employer_id
27
- field :security_code
28
- field :blood_alcohol_content, type: Float, default: -> { 0.0 }
29
- field :last_drink_taken_at, type: Date,
30
- default: -> { 1.day.ago.in_time_zone('Alaska') }
31
-
32
- # Geo
33
- field :location, type: Point
34
-
35
- index age: 1
36
- index addresses: 1
37
- index dob: 1
38
- index name: 1
39
- index title: 1
40
- index({ ssn: 1 }, unique: true)
41
-
42
- validates_format_of :ssn, without: /\$\$\$/
43
-
44
- attr_reader :rescored
45
-
46
- # attr_protected :security_code, :owner_id
47
-
48
- embeds_many :addresses, as: :addressable do
49
- def extension
50
- 'Testing'
51
- end
52
-
53
- def find_by_street(street)
54
- @target.select { |doc| doc.street == street }
55
- end
56
- end
57
-
58
- accepts_nested_attributes_for :addresses
59
-
60
- scope :minor, -> { where(:age.lt => 18) }
61
- scope :without_ssn, -> { without(:ssn) }
62
-
63
- def update_addresses
64
- addresses.each do |address|
65
- address.street = 'Updated Address'
66
- end
67
- end
68
-
69
- def employer=(emp)
70
- self.employer_id = emp.id
71
- end
72
-
73
- class << self
74
- def accepted
75
- criteria.where(terms: true)
76
- end
77
-
78
- def knight
79
- criteria.where(title: 'Sir')
80
- end
81
-
82
- def old
83
- criteria.where(age: { '$gt' => 50 })
84
- end
85
- end
86
- end
87
-
88
- # Inheritance test
89
- class Doctor < Person
90
- field :specialty
91
- end
data/spec/models/phone.rb DELETED
@@ -1,8 +0,0 @@
1
- # Sample spec class
2
- class Phone
3
- include Mongoid::Document
4
- field :number
5
-
6
- embeds_one :country_code
7
- embedded_in :person
8
- end
data/spec/models/place.rb DELETED
@@ -1,13 +0,0 @@
1
- # Sample spec class
2
- class Place
3
- include Mongoid::Document
4
- include Mongoid::Geospatial
5
-
6
- field :name, type: String
7
- field :location, type: Point, spatial: true
8
-
9
- has_one :rating, as: :ratable
10
-
11
- spatial_index :location
12
- spatial_scope :location
13
- end
data/spec/models/river.rb DELETED
@@ -1,22 +0,0 @@
1
- # Sample spec class
2
- class River
3
- include Mongoid::Document
4
- include Mongoid::Geospatial
5
-
6
- field :name, type: String
7
- field :length, type: Integer
8
- field :discharge, type: Integer
9
- field :course, type: LineString, spatial: true
10
- # set return_array to true if you do not want a hash returned all the time
11
- field :source, type: Point, spatial: true
12
- field :mouth, type: Point, spatial: { lat: 'latitude', lng: 'longitude' }
13
- field :mouth_array, type: Array, spatial: { return_array: true }
14
-
15
- # simplified spatial indexing
16
- # you can only index one field in mongodb < 1.9
17
- spatial_index :source
18
- # alternatives
19
- # index [[ :spatial, Mongo::GEO2D ]], {min:-400, max:400}
20
- # index [[ :spatial, Mongo::GEO2D ]], {bit:32}
21
- # index [[ :spatial, Mongo::GEO2D ],:name]
22
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Mongoid::Geospatial::Config do
4
- context 'point' do
5
- it 'uses LonLat by default' do
6
- expect(Mongoid::Geospatial.config.point.x).to eq Mongoid::Geospatial.lng_symbols
7
- expect(Mongoid::Geospatial.config.point.y).to eq Mongoid::Geospatial.lat_symbols
8
- end
9
- context 'configured as latlon' do
10
- before do
11
- Mongoid::Geospatial.configure do |config|
12
- config.point.x = Mongoid::Geospatial.lat_symbols
13
- config.point.y = Mongoid::Geospatial.lng_symbols
14
- end
15
- end
16
- it 'uses latlon' do
17
- expect(Mongoid::Geospatial.config.point.x).to eq Mongoid::Geospatial.lat_symbols
18
- expect(Mongoid::Geospatial.config.point.y).to eq Mongoid::Geospatial.lng_symbols
19
- end
20
- end
21
- end
22
- end
@@ -1,8 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Mongoid::Geospatial::Box do
4
- it 'should work' do
5
- alarm = Alarm.new(area: [[1, 2], [3, 4]])
6
- expect(alarm.area).to be_a Mongoid::Geospatial::Box
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Mongoid::Geospatial::Circle do
4
- it 'should work' do
5
- alarm = Alarm.new(radius: [[1, 2], 3])
6
- expect(alarm.radius).to be_a Mongoid::Geospatial::Circle
7
- end
8
- end
@@ -1,78 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Mongoid::Geospatial::LineString do
4
- describe '(de)mongoize' do
5
- it 'should support a field mapped as linestring' do
6
- river = River.new(course: [[5, 5], [6, 5], [6, 6], [5, 6]])
7
- expect(river.course).to be_a Mongoid::Geospatial::LineString
8
- expect(river.course).to eq([[5, 5], [6, 5], [6, 6], [5, 6]])
9
- end
10
-
11
- it 'should update line string too' do
12
- river = River.create!(name: 'Amazonas')
13
- river.course = [[1, 1], [1, 1], [9, 9], [9, 9]]
14
- river.save
15
- expect(River.first.course).to eq(river.course)
16
- end
17
-
18
- it 'should line_string += point nicely' do
19
- river = River.create!(name: 'Amazonas', course: [[1, 1], [9, 9]])
20
- river.course += [[10, 10]]
21
- river.save
22
- expect(River.first.course).to eq([[1, 1], [9, 9], [10, 10]])
23
- end
24
-
25
- it 'should NOT parent.line_string << point nicely (mongoid doesnt track <<)' do
26
- river = River.create!(name: 'Amazonas', course: [[1, 1], [9, 9]])
27
- river.course << [10, 10]
28
- river.save
29
- expect(River.first.course).to eq([[1, 1], [9, 9]])
30
- end
31
-
32
- it 'should have same obj id' do
33
- pending 'Mongoid Issue #...'
34
- river = River.create!(name: 'Amazonas', course: [[1, 1], [9, 9]])
35
- expect(river.course.object_id).to eq(river.course.object_id)
36
- end
37
-
38
- it 'should have same obj id ary' do
39
- river = River.create!(name: 'Amazonas', mouth_array: [[1, 1], [9, 9]])
40
- expect(river.mouth_array.object_id).to eq(river.mouth_array.object_id)
41
- end
42
-
43
- it 'should support a field mapped as linestring' do
44
- River.create!(course: [[5, 5], [6, 5], [6, 6], [5, 6]])
45
- expect(River.first.course).to eq([[5, 5], [6, 5], [6, 6], [5, 6]])
46
- end
47
-
48
- it 'should have a bounding box' do
49
- l = Mongoid::Geospatial::LineString.new [[1, 5], [6, 5], [6, 6], [5, 6]]
50
- expect(l.bbox).to eq([[1, 5], [6, 6]])
51
- end
52
-
53
- it 'should have a geom box' do
54
- l = Mongoid::Geospatial::LineString.new [[1, 1], [5, 5]]
55
- expect(l.geom_box).to eq([[1, 1], [1, 5], [5, 5], [5, 1], [1, 1]])
56
- end
57
-
58
- it 'should have a geom box' do
59
- l = Mongoid::Geospatial::LineString.new [[1, 1], [2, 2], [3, 4], [5, 5]]
60
- expect(l.geom_box).to eq([[1, 1], [1, 5], [5, 5], [5, 1], [1, 1]])
61
- end
62
-
63
- it 'should have a center point' do
64
- l = Mongoid::Geospatial::LineString.new [[1, 1], [1, 1], [9, 9], [9, 9]]
65
- expect(l.center).to eq([5.0, 5.0])
66
- end
67
-
68
- it 'should have a radius helper' do
69
- l = Mongoid::Geospatial::LineString.new [[1, 1], [1, 1], [9, 9], [9, 9]]
70
- expect(l.radius(10)).to eq([[5.0, 5.0], 10])
71
- end
72
-
73
- it 'should have a radius sphere' do
74
- l = Mongoid::Geospatial::LineString.new [[1, 1], [1, 1], [9, 9], [9, 9]]
75
- expect(l.radius_sphere(10)[1]).to be_within(0.001).of(0.001569)
76
- end
77
- end
78
- end