mongoid-geospatial 5.1.0 → 7.0.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 +4 -4
- data/.rubocop.yml +7 -5
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -24
- data/README.md +23 -38
- data/lib/mongoid/geospatial/fields/point.rb +13 -1
- data/lib/mongoid/geospatial/helpers/sphere.rb +1 -1
- data/lib/mongoid/geospatial/version.rb +1 -1
- data/lib/mongoid/geospatial.rb +101 -26
- data/{bench → spec}/bench +0 -0
- data/spec/models/bar.rb +1 -0
- data/spec/models/person.rb +0 -5
- data/spec/models/river.rb +7 -7
- data/spec/mongoid/geospatial/fields/line_string_spec.rb +3 -4
- data/spec/mongoid/geospatial/fields/point_spec.rb +29 -2
- data/spec/mongoid/geospatial/fields/polygon_spec.rb +3 -3
- data/spec/mongoid/geospatial/geospatial_spec.rb +79 -7
- data/spec/mongoid/geospatial/helpers/spatial_spec.rb +4 -3
- data/spec/mongoid/geospatial/helpers/sphere_spec.rb +4 -2
- data/spec/mongoid.yml +298 -0
- data/spec/spec_helper.rb +8 -13
- metadata +7 -10
- data/.rubocop_todo.yml +0 -93
- data/Dangerfile +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c175628dbf99da911bb81c3c25b2665b3547506f910366a53d43eaabea99e410
|
4
|
+
data.tar.gz: 8e38f228cc16e9a17cbe44dd2be01bd06e989d5e91d968a9b50a1885cc12eb8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a09b65028e7d0b27a88383dac691372e6b456ad0d72b3ef0159e8e9e33d7f6da78cb250038c6d592bbb667d9a6f6f864ac1ae8278eaed41b69277d0290a47399
|
7
|
+
data.tar.gz: 843567a6bbe62c5551cd962c70a927e2dd8e19968c741ea014e384cf942b99aa75fa382969fe139cc07c835249fb7d864421713cb5e324e0495615fc14b7d30e
|
data/.rubocop.yml
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
- vendor/**/*
|
4
|
-
- bin/**/*
|
1
|
+
# Omakase Ruby styling for Rails
|
2
|
+
inherit_gem: { rubocop-rails-omakase: rubocop.yml }
|
5
3
|
|
6
|
-
|
4
|
+
# Overwrite or add rules to create your own house style
|
5
|
+
#
|
6
|
+
# # Use `[a, [b, c]]` not `[ a, [ b, c ] ]`
|
7
|
+
# Layout/SpaceInsideArrayLiteralBrackets:
|
8
|
+
# Enabled: false
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -1,37 +1,17 @@
|
|
1
|
-
source '
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
when 'HEAD'
|
5
|
-
gem 'mongoid', github: 'mongodb/mongoid'
|
6
|
-
when /^7/
|
7
|
-
gem 'mongoid', '~> 7.0.0'
|
8
|
-
when /^6/
|
9
|
-
gem 'mongoid', '~> 6.0.0'
|
10
|
-
when /^5/
|
11
|
-
gem 'mongoid', '~> 5.0'
|
12
|
-
else
|
13
|
-
gem 'mongoid', version
|
14
|
-
end
|
3
|
+
gem 'mongoid'
|
15
4
|
|
16
5
|
gemspec
|
17
6
|
|
18
7
|
group :development, :test do
|
19
8
|
gem 'fuubar'
|
9
|
+
gem 'rake'
|
20
10
|
gem 'guard'
|
21
11
|
gem 'guard-rspec'
|
22
|
-
gem '
|
23
|
-
gem 'pry'
|
24
|
-
gem 'rake'
|
25
|
-
gem 'yard'
|
12
|
+
gem 'rubocop'
|
26
13
|
end
|
27
14
|
|
28
15
|
group :test do
|
29
16
|
gem 'coveralls', require: false if ENV['CI']
|
30
|
-
gem 'dbf'
|
31
|
-
gem 'georuby'
|
32
|
-
gem 'mongoid-danger', '~> 0.1.0', require: false
|
33
|
-
gem 'nokogiri'
|
34
|
-
gem 'rgeo'
|
35
|
-
gem 'rspec'
|
36
|
-
gem 'rubocop', '0.60.0'
|
37
17
|
end
|
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
Mongoid Geospatial
|
2
|
-
==================
|
1
|
+
# Mongoid Geospatial
|
3
2
|
|
4
3
|
A Mongoid Extension that simplifies the use of MongoDB spatial features.
|
5
4
|
|
@@ -8,8 +7,7 @@ A Mongoid Extension that simplifies the use of MongoDB spatial features.
|
|
8
7
|
[](https://coveralls.io/github/mongoid/mongoid-geospatial?branch=master)
|
9
8
|
[](https://travis-ci.org/mongoid/mongoid-geospatial)
|
10
9
|
|
11
|
-
Quick Start
|
12
|
-
-----------
|
10
|
+
## Quick Start
|
13
11
|
|
14
12
|
This gem focuses on (making helpers for) MongoDB's spatial features using Mongoid 5, 6 and 7.
|
15
13
|
|
@@ -60,17 +58,16 @@ Or programatically:
|
|
60
58
|
Place.create_indexes
|
61
59
|
```
|
62
60
|
|
63
|
-
Points
|
64
|
-
------
|
61
|
+
## Points
|
65
62
|
|
66
63
|
This gem defines a specific `Point` class under the Mongoid::Geospatial namespace. Make sure to use `type: ::Mongoid::Geospatial::Point` to avoid name errors or collisions with other `Point` classes you might already have defined `NameError`s.
|
67
64
|
|
68
65
|
Currently, MongoDB supports query operations on 2D points only, so that's what this lib does. All geometries apart from points are just arrays in the database. Here's is how you can input a point as:
|
69
66
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
67
|
+
- longitude latitude array in that order - [long,lat] ([x, y])
|
68
|
+
- an unordered hash with latitude key(:lat, :latitude) and a longitude key(:lon, :long, :lng, :longitude)
|
69
|
+
- an ordered hash with longitude as the first item and latitude as the second item; this hash does not have include the latitude and longitude keys
|
70
|
+
- anything with the a method #to_xy or #to_lng_lat that converts itself to [long, lat] array
|
74
71
|
|
75
72
|
_Note: the convention of having longitude as the first coordinate may vary for other libraries. For instance, Google Maps often refer to "LatLng". Make sure you keep those differences in mind. See below for how to configure this library for LatLng._
|
76
73
|
|
@@ -131,8 +128,7 @@ house.area.bbox # Returns polygon bounding_box (envelope)
|
|
131
128
|
house.area.center # Returns calculate middle point
|
132
129
|
```
|
133
130
|
|
134
|
-
Model Setup
|
135
|
-
-----------
|
131
|
+
## Model Setup
|
136
132
|
|
137
133
|
You can create Point, Line, Circle, Box and Polygon on your models:
|
138
134
|
|
@@ -157,8 +153,7 @@ class CrazyGeom
|
|
157
153
|
end
|
158
154
|
```
|
159
155
|
|
160
|
-
Helpers
|
161
|
-
-------
|
156
|
+
## Helpers
|
162
157
|
|
163
158
|
You can use `spatial: true` to add a '2d' index automatically,
|
164
159
|
No need for `spatial_index :location`:
|
@@ -181,8 +176,7 @@ field :location, type: Point, delegate: true
|
|
181
176
|
|
182
177
|
Now instead of `instance.location.x` you may call `instance.x`.
|
183
178
|
|
184
|
-
Nearby
|
185
|
-
------
|
179
|
+
## Nearby
|
186
180
|
|
187
181
|
You can add a `spatial_scope` on your models. So you can query:
|
188
182
|
|
@@ -202,8 +196,7 @@ Good when you're drunk. Just add to your model:
|
|
202
196
|
spatial_scope :<field>
|
203
197
|
```
|
204
198
|
|
205
|
-
Geometry
|
206
|
-
--------
|
199
|
+
## Geometry
|
207
200
|
|
208
201
|
You can also store Circle, Box, Line (LineString) and Polygons.
|
209
202
|
Some helper methods are available to them:
|
@@ -224,8 +217,7 @@ polygon.radius(5) # [[1.0, 1.0], 5]
|
|
224
217
|
polygon.radius_sphere(5) # [[1.0, 1.0], 0.00048..]
|
225
218
|
```
|
226
219
|
|
227
|
-
Query
|
228
|
-
-----
|
220
|
+
## Query
|
229
221
|
|
230
222
|
Before you proceed, make sure you have read this:
|
231
223
|
|
@@ -237,21 +229,21 @@ http://www.rubydoc.info/github/mongoid/origin/Origin/Selectable
|
|
237
229
|
|
238
230
|
You can use Geometry instance directly on any query:
|
239
231
|
|
240
|
-
|
232
|
+
- near
|
241
233
|
|
242
234
|
```ruby
|
243
235
|
Bar.near(location: person.house)
|
244
236
|
Bar.where(:location.near => person.house)
|
245
237
|
```
|
246
238
|
|
247
|
-
|
239
|
+
- near_sphere
|
248
240
|
|
249
241
|
```ruby
|
250
242
|
Bar.near_sphere(location: person.house)
|
251
243
|
Bar.where(:location.near_sphere => person.house)
|
252
244
|
```
|
253
245
|
|
254
|
-
|
246
|
+
- within_polygon
|
255
247
|
|
256
248
|
```ruby
|
257
249
|
Bar.within_polygon(location: [[[x,y],...[x,y]]])
|
@@ -259,13 +251,11 @@ Bar.within_polygon(location: [[[x,y],...[x,y]]])
|
|
259
251
|
Bar.within_polygon(location: street.bbox)
|
260
252
|
```
|
261
253
|
|
262
|
-
|
263
|
-
|
264
|
-
|
254
|
+
- intersects_line
|
255
|
+
- intersects_point
|
256
|
+
- intersects_polygon
|
265
257
|
|
266
|
-
|
267
|
-
External Libraries
|
268
|
-
------------------
|
258
|
+
## External Libraries
|
269
259
|
|
270
260
|
We currently support GeoRuby and RGeo.
|
271
261
|
If you require one of those, a #to_geo and #to_rgeo, respectivelly,
|
@@ -338,8 +328,7 @@ end
|
|
338
328
|
|
339
329
|
You will need to manually migrate any existing `Point` data if you change configuration in an existing system.
|
340
330
|
|
341
|
-
This Fork
|
342
|
-
---------
|
331
|
+
## This Fork
|
343
332
|
|
344
333
|
This fork is not backwards compatible with 'mongoid_spacial'.
|
345
334
|
This fork delegates calculations to external libs.
|
@@ -370,8 +359,7 @@ field :source, type: Point, spatial: true # or sphere: true
|
|
370
359
|
|
371
360
|
Beware the 't' and 'c' issue. It's spaTial.
|
372
361
|
|
373
|
-
Troubleshooting
|
374
|
-
---------------
|
362
|
+
## Troubleshooting
|
375
363
|
|
376
364
|
**Mongo::OperationFailure: can't find special index: 2d**
|
377
365
|
|
@@ -387,15 +375,12 @@ Programatically
|
|
387
375
|
Model.create_indexes
|
388
376
|
```
|
389
377
|
|
390
|
-
Contributing
|
391
|
-
------------
|
378
|
+
## Contributing
|
392
379
|
|
393
380
|
See [CONTRIBUTING](CONTRIBUTING.md).
|
394
381
|
|
395
|
-
License
|
396
|
-
-------
|
382
|
+
## License
|
397
383
|
|
398
384
|
Copyright (c) 2009-2017 Mongoid Geospatial Authors
|
399
385
|
|
400
386
|
MIT License, see [MIT-LICENSE](MIT-LICENSE).
|
401
|
-
|
@@ -49,7 +49,7 @@ module Mongoid
|
|
49
49
|
# @return [Array] with [self, radius]
|
50
50
|
#
|
51
51
|
def radius(r = 1)
|
52
|
-
[mongoize, r]
|
52
|
+
[ mongoize, r ]
|
53
53
|
end
|
54
54
|
|
55
55
|
#
|
@@ -85,6 +85,18 @@ module Mongoid
|
|
85
85
|
"#{x}, #{y}"
|
86
86
|
end
|
87
87
|
|
88
|
+
#
|
89
|
+
# Point definition as GeoJSON
|
90
|
+
#
|
91
|
+
# "x, y"
|
92
|
+
#
|
93
|
+
# @return [String] Point as comma separated String
|
94
|
+
#
|
95
|
+
def to_geo_json
|
96
|
+
# Return a GeoJSON point hash that MongoDB can use
|
97
|
+
{ type: "Point", coordinates: [x, y] }
|
98
|
+
end
|
99
|
+
|
88
100
|
#
|
89
101
|
# Point inverse/reverse
|
90
102
|
#
|
data/lib/mongoid/geospatial.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'mongoid'
|
2
|
-
|
3
|
-
# require 'active_support/concern'
|
2
|
+
require 'active_support/concern' # Explicitly require for `extend ActiveSupport::Concern`
|
4
3
|
require 'mongoid/geospatial/helpers/spatial'
|
5
4
|
require 'mongoid/geospatial/helpers/sphere'
|
6
5
|
require 'mongoid/geospatial/helpers/delegate'
|
@@ -55,7 +54,6 @@ module Mongoid
|
|
55
54
|
@@earth_radius = EARTH_RADIUS.dup
|
56
55
|
|
57
56
|
included do
|
58
|
-
# attr_accessor :geo
|
59
57
|
cattr_accessor :spatial_fields, :spatial_fields_indexed
|
60
58
|
self.spatial_fields = []
|
61
59
|
self.spatial_fields_indexed = []
|
@@ -72,14 +70,10 @@ module Mongoid
|
|
72
70
|
# Methods applied to Document's class
|
73
71
|
module ClassMethods
|
74
72
|
#
|
75
|
-
#
|
73
|
+
# Creates a 2d spatial index for the given field.
|
76
74
|
#
|
77
|
-
#
|
78
|
-
# @param [
|
79
|
-
# @param [Hash] options options for spatial_index
|
80
|
-
#
|
81
|
-
# http://www.mongodb.org/display/DOCS/Geospatial+Indexing
|
82
|
-
# #GeospatialIndexing-geoNearCommand
|
75
|
+
# @param name [String, Symbol] The name of the field to index.
|
76
|
+
# @param options [Hash] Additional options for the index.
|
83
77
|
#
|
84
78
|
def spatial_index(name, options = {})
|
85
79
|
spatial_fields_indexed << name
|
@@ -87,36 +81,117 @@ module Mongoid
|
|
87
81
|
end
|
88
82
|
|
89
83
|
#
|
90
|
-
# Creates
|
91
|
-
#
|
84
|
+
# Creates a 2dsphere index for the given field, suitable for spherical geometry calculations.
|
92
85
|
#
|
93
|
-
# @param [String,Symbol] name
|
94
|
-
# @param [Hash]
|
86
|
+
# @param name [String, Symbol] The name of the field to index.
|
87
|
+
# @param options [Hash] Additional options for the index.
|
95
88
|
#
|
96
|
-
|
97
|
-
# #GeospatialIndexing-geoNearCommand
|
98
|
-
def sphere_index(name, options = {})
|
89
|
+
def spherical_index(name, options = {})
|
99
90
|
spatial_fields_indexed << name
|
100
91
|
index({ name => '2dsphere' }, options)
|
101
92
|
end
|
102
93
|
|
103
94
|
#
|
104
|
-
#
|
95
|
+
# Defines a class method to find the closest document to a given point
|
96
|
+
# using the specified spatial field via the `geoNear` command.
|
105
97
|
#
|
98
|
+
# @param field_name [String, Symbol] The name of the spatial field to query.
|
99
|
+
# @param default_geo_near_options [Hash] Default options for the geoNear command
|
100
|
+
# (e.g., `{ spherical: true, max_distance: 1000 }`).
|
101
|
+
# The `key` option will be automatically set to `field_name`.
|
106
102
|
#
|
107
|
-
#
|
108
|
-
#
|
103
|
+
# Example:
|
104
|
+
# class Place
|
105
|
+
# include Mongoid::Document
|
106
|
+
# include Mongoid::Geospatial
|
107
|
+
# field :location, type: Array
|
108
|
+
# spherical_index :location # Assumes a 2dsphere index for spherical queries
|
109
|
+
# spatial_scope :location, spherical: true # Default to spherical for this scope
|
110
|
+
# end
|
109
111
|
#
|
110
|
-
#
|
111
|
-
# #
|
112
|
-
|
112
|
+
# Place.closest_to_location([lon, lat]) # Finds the single closest place
|
113
|
+
# Place.closest_to_location([lon, lat], max_distance: 500) # Override/add options
|
114
|
+
#
|
115
|
+
def spatial_scope(field_name, default_geo_near_options = {})
|
116
|
+
method_name = :"closest_to_#{field_name}"
|
117
|
+
field_name_sym = field_name.to_sym
|
118
|
+
# key_name = field_name.to_s # Original geoNear used 'key' for field name
|
119
|
+
|
113
120
|
singleton_class.class_eval do
|
114
|
-
|
115
|
-
|
116
|
-
|
121
|
+
define_method(method_name) do |coordinates, additional_options = {}|
|
122
|
+
# `coordinates` should be [lon, lat] or a GeoJSON Point hash
|
123
|
+
# `self` here is the class (e.g., Bar)
|
124
|
+
|
125
|
+
merged_options = default_geo_near_options.merge(additional_options)
|
126
|
+
|
127
|
+
# Determine if spherical based on options or field definition
|
128
|
+
is_spherical = if merged_options.key?(:spherical)
|
129
|
+
merged_options[:spherical]
|
130
|
+
else
|
131
|
+
# self.fields uses string keys for field names
|
132
|
+
field_def = self.fields[field_name.to_s]
|
133
|
+
field_def && field_def.options[:sphere]
|
134
|
+
end
|
135
|
+
query_operator = is_spherical ? :near_sphere : :near
|
136
|
+
|
137
|
+
# Prepare the value for the geospatial operator
|
138
|
+
# Mongoid::Geospatial::Point.mongoize ensures coordinates are in [lng, lat] array format
|
139
|
+
# from various input types (Point object, array, string, hash).
|
140
|
+
mongoized_coords = Mongoid::Geospatial::Point.mongoize(coordinates)
|
141
|
+
|
142
|
+
geo_query_value = if merged_options[:max_distance]
|
143
|
+
{
|
144
|
+
# Using $geometry for clarity when $maxDistance is used,
|
145
|
+
# which is standard for $near/$nearSphere operators.
|
146
|
+
"$geometry" => { type: "Point", coordinates: mongoized_coords },
|
147
|
+
"$maxDistance" => merged_options[:max_distance].to_f
|
148
|
+
}
|
149
|
+
else
|
150
|
+
mongoized_coords # Simple array [lng, lat] for the operator
|
151
|
+
end
|
152
|
+
|
153
|
+
# Start with a base criteria, applying an optional filter query
|
154
|
+
current_criteria = merged_options[:query] ? self.where(merged_options[:query]) : self.all
|
155
|
+
|
156
|
+
# Apply the geospatial query. $near and $nearSphere queries return sorted results.
|
157
|
+
current_criteria.where(field_name_sym.send(query_operator) => geo_query_value)
|
117
158
|
end
|
118
159
|
end
|
119
160
|
end
|
161
|
+
|
162
|
+
#
|
163
|
+
# Provides a convenient way to find documents near a given set of coordinates.
|
164
|
+
# It automatically uses the first spatial field defined in the model and
|
165
|
+
# determines whether to use a planar (.near) or spherical (.near_sphere)
|
166
|
+
# query based on the field's definition options (`spatial: true` vs `sphere: true`).
|
167
|
+
#
|
168
|
+
# @param coordinates [Array, Mongoid::Geospatial::Point] The coordinates (e.g., [lon, lat])
|
169
|
+
# or a Point object to find documents near to.
|
170
|
+
# @param _options [Hash] Optional hash for future extensions (currently unused).
|
171
|
+
#
|
172
|
+
# @return [Mongoid::Criteria] A criteria object for the query.
|
173
|
+
#
|
174
|
+
# Example:
|
175
|
+
# Bar.nearby([10, 20])
|
176
|
+
# Alarm.nearby(my_point_object)
|
177
|
+
#
|
178
|
+
def nearby(coordinates, _options = {})
|
179
|
+
if self.spatial_fields.empty?
|
180
|
+
raise "No spatial fields defined for #{self.name} to use with .nearby. " \
|
181
|
+
"Mark a field with 'spatial: true' or 'sphere: true'."
|
182
|
+
end
|
183
|
+
|
184
|
+
field_name_sym = self.spatial_fields.first.to_sym
|
185
|
+
field_definition = self.fields[field_name_sym.to_s]
|
186
|
+
|
187
|
+
unless field_definition
|
188
|
+
raise "Could not find field definition for spatial field: #{field_name_sym}"
|
189
|
+
end
|
190
|
+
|
191
|
+
query_operator = field_definition.options[:sphere] ? :near_sphere : :near
|
192
|
+
|
193
|
+
criteria.where(field_name_sym.send(query_operator) => coordinates)
|
194
|
+
end
|
120
195
|
end
|
121
196
|
end
|
122
197
|
end
|
data/{bench → spec}/bench
RENAMED
File without changes
|
data/spec/models/bar.rb
CHANGED
data/spec/models/person.rb
CHANGED
@@ -60,11 +60,6 @@ class Person
|
|
60
60
|
scope :minor, -> { where(:age.lt => 18) }
|
61
61
|
scope :without_ssn, -> { without(:ssn) }
|
62
62
|
|
63
|
-
def score_with_rescoring=(score)
|
64
|
-
@rescored = score.to_i + 20
|
65
|
-
self.score_without_rescoring = score
|
66
|
-
end
|
67
|
-
|
68
63
|
def update_addresses
|
69
64
|
addresses.each do |address|
|
70
65
|
address.street = 'Updated Address'
|
data/spec/models/river.rb
CHANGED
@@ -3,14 +3,14 @@ class River
|
|
3
3
|
include Mongoid::Document
|
4
4
|
include Mongoid::Geospatial
|
5
5
|
|
6
|
-
field :name,
|
7
|
-
field :length,
|
8
|
-
field :discharge,
|
9
|
-
field :course,
|
6
|
+
field :name, type: String
|
7
|
+
field :length, type: Integer
|
8
|
+
field :discharge, type: Integer
|
9
|
+
field :course, type: LineString, spatial: true
|
10
10
|
# set return_array to true if you do not want a hash returned all the time
|
11
|
-
field :source,
|
12
|
-
field :mouth,
|
13
|
-
field :mouth_array, type: Array,
|
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
14
|
|
15
15
|
# simplified spatial indexing
|
16
16
|
# you can only index one field in mongodb < 1.9
|
@@ -22,12 +22,11 @@ describe Mongoid::Geospatial::LineString do
|
|
22
22
|
expect(River.first.course).to eq([[1, 1], [9, 9], [10, 10]])
|
23
23
|
end
|
24
24
|
|
25
|
-
it 'should parent.line_string << point nicely' do
|
26
|
-
pending 'Mongoid Issue #...'
|
25
|
+
it 'should NOT parent.line_string << point nicely (mongoid doesnt track <<)' do
|
27
26
|
river = River.create!(name: 'Amazonas', course: [[1, 1], [9, 9]])
|
28
|
-
river.course
|
27
|
+
river.course << [10, 10]
|
29
28
|
river.save
|
30
|
-
expect(River.first.course).to eq([[1, 1], [9, 9]
|
29
|
+
expect(River.first.course).to eq([[1, 1], [9, 9]])
|
31
30
|
end
|
32
31
|
|
33
32
|
it 'should have same obj id' do
|
@@ -53,6 +53,28 @@ describe Mongoid::Geospatial::Point do
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
+
it "should have a to_s method" do
|
57
|
+
bar = Bar.create!(name: "Moe's", location: [1, 2])
|
58
|
+
expect(bar.location.to_s).to eq('1.0, 2.0')
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should have a to_s method" do
|
62
|
+
bar = Bar.create!(name: "Moe's", location: [1.0009, 21.009])
|
63
|
+
expect(bar.location.to_s).to eq('1.0009, 21.009')
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should have a to_geo_json method" do
|
67
|
+
bar = Bar.create!(name: "Moe's", location: [1.0009, 21.009])
|
68
|
+
expect(bar.location.to_geo_json).to eq({
|
69
|
+
type: "Point", coordinates: [1.0009, 21.009]
|
70
|
+
})
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should have a to_json method" do
|
74
|
+
bar = Bar.create!(name: "Moe's", location: [1.0009, 21.009])
|
75
|
+
expect(bar.location.to_json).to eq("[1.0009,21.009]")
|
76
|
+
end
|
77
|
+
|
56
78
|
it 'should have #reverse to get lat, lon' do
|
57
79
|
bar = Bar.create!(name: "Moe's", location: [1, 2])
|
58
80
|
expect(bar.location.reverse).to eq([2, 1])
|
@@ -147,7 +169,12 @@ describe Mongoid::Geospatial::Point do
|
|
147
169
|
end
|
148
170
|
|
149
171
|
it 'returns the documents sorted closest to furthest' do
|
150
|
-
expect(Bar.
|
172
|
+
expect(Bar.closest_to_location(jim.location).to_a)
|
173
|
+
.to eq([paris, prague, berlin])
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'returns the documents sorted closest to furthest' do
|
177
|
+
expect(Bar.where(:location.near => jim.location).to_a)
|
151
178
|
.to eq([paris, prague, berlin])
|
152
179
|
end
|
153
180
|
|
@@ -258,7 +285,7 @@ describe Mongoid::Geospatial::Point do
|
|
258
285
|
|
259
286
|
describe 'with rgeo' do
|
260
287
|
describe 'instantiated' do
|
261
|
-
let(:bar) { Bar.
|
288
|
+
let(:bar) { Bar.new(name: 'Vitinho', location: [10, 10]) }
|
262
289
|
|
263
290
|
it 'should demongoize to rgeo' do
|
264
291
|
expect(bar.location.class).to eql(Mongoid::Geospatial::Point)
|
@@ -49,20 +49,20 @@ describe Mongoid::Geospatial::Polygon do
|
|
49
49
|
Farm.create_indexes
|
50
50
|
end
|
51
51
|
|
52
|
-
let
|
52
|
+
let(:ranch) do
|
53
53
|
Farm.create!(name: 'Ranch',
|
54
54
|
area: [[1, 1], [3, 3], [3, 1], [1, 1]],
|
55
55
|
geom: [2, 2])
|
56
56
|
end
|
57
57
|
|
58
|
-
let
|
58
|
+
let(:farm) do
|
59
59
|
Farm.create!(name: 'Farm',
|
60
60
|
area: [[47, 1], [48, 1.5], [49, 3], [49, 1], [47, 1]],
|
61
61
|
geom: [48, 1.28])
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'returns the documents within a box' do
|
65
|
-
query = Farm.
|
65
|
+
query = Farm.geo_spatial(:geom.within_polygon => [ranch.area])
|
66
66
|
expect(query.to_a).to eq([ranch])
|
67
67
|
end
|
68
68
|
|
@@ -29,25 +29,97 @@ describe Mongoid::Geospatial do
|
|
29
29
|
before do
|
30
30
|
Bar.create_indexes
|
31
31
|
end
|
32
|
+
after do
|
33
|
+
Bar.collection.indexes.drop_all
|
34
|
+
end
|
32
35
|
|
33
|
-
let!(:
|
34
|
-
Bar.create(name: '
|
36
|
+
let!(:moes) do
|
37
|
+
Bar.create!(name: "Moe's", location: [-73.77694444, 40.63861111])
|
35
38
|
end
|
36
39
|
|
37
|
-
let!(:
|
38
|
-
Bar.create(name: '
|
40
|
+
let!(:rose) do
|
41
|
+
Bar.create!(name: 'Rosa', location: [-118.40, 33.94])
|
42
|
+
end
|
43
|
+
|
44
|
+
let!(:jane) do
|
45
|
+
Bar.create!(name: "Jane's", location: [1, 1])
|
46
|
+
end
|
47
|
+
|
48
|
+
let!(:foo) do
|
49
|
+
Bar.create!(name: "Foo", location: [3, 3])
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should work specifing center and different location foo' do
|
53
|
+
expect(Bar.nearby(foo.location)).to be_a Mongoid::Criteria
|
54
|
+
expect(Bar.nearby(foo.location).selector).to eq({"location" => {"$near" => [3.0, 3.0]}})
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should work specifing center and different location moes' do
|
58
|
+
expect(Bar.nearby(moes.location).limit(2)).to eq([moes, rose])
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should work finding first' do
|
62
|
+
expect(Bar.nearby(moes.location).first).to eq(moes)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'really should work find first nearby' do
|
66
|
+
expect(Bar.count).to eq(4)
|
67
|
+
expect(Bar.nearby([1, 1]).to_a).to eq([jane, foo, moes, rose])
|
68
|
+
expect(Bar.nearby([2, 2]).to_a.first).to eq(jane)
|
69
|
+
# THIS WILL FAIL MONGOID ISSUE
|
70
|
+
# expect(Bar.nearby(rose.location).first).to eq(rose)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should work specifing first' do
|
74
|
+
bars = Bar.nearby(rose.location).to_a
|
75
|
+
expect(bars.first).to eq(rose)
|
39
76
|
end
|
40
77
|
|
41
|
-
it 'should work specifing
|
42
|
-
expect(Bar.nearby(
|
78
|
+
it 'should work specifing first' do
|
79
|
+
expect(Bar.nearby(rose.location).to_a.first).to eq(rose)
|
43
80
|
end
|
81
|
+
|
82
|
+
it 'should work specifing first' do
|
83
|
+
expect(Bar.nearby(rose.location).to_a.first).to eq(rose)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should work specifing first' do
|
87
|
+
expect(Bar.nearby(rose.location).first).to eq(rose)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'returns the documents sorted closest to furthest' do
|
91
|
+
expect(Bar.closest_to_location(rose.location).to_a)
|
92
|
+
.to eq([rose, moes, jane, foo])
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'returns the documents sorted closest to furthest' do
|
96
|
+
expect(Bar.closest_to_location(rose.location).limit(2))
|
97
|
+
.to eq([rose, moes])
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'returns the documents sorted closest to furthest' do
|
101
|
+
expect(Bar.closest_to_location(rose.location).first).to eq(rose)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'returns the documents sorted closest to furthest' do
|
105
|
+
expect(Bar.closest_to_location(rose.location).to_a)
|
106
|
+
.to eq([rose, moes, jane, foo])
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should work specifing center and different location foo' do
|
110
|
+
expect(Bar.closest_to_location(foo.location)).to be_a Mongoid::Criteria
|
111
|
+
expect(Bar.closest_to_location(foo.location).selector).to eq({"location" => {"$near" => [3.0, 3.0]}})
|
112
|
+
end
|
113
|
+
|
44
114
|
end
|
45
115
|
|
46
116
|
context '#nearby 2dsphere' do
|
47
117
|
before do
|
48
118
|
Alarm.create_indexes
|
49
119
|
end
|
50
|
-
|
120
|
+
after do
|
121
|
+
Alarm.collection.indexes.drop_all
|
122
|
+
end
|
51
123
|
let!(:jfk) do
|
52
124
|
Alarm.create(name: 'jfk', spot: [-73.77694444, 40.63861111])
|
53
125
|
end
|
@@ -12,9 +12,10 @@ describe Mongoid::Fields do
|
|
12
12
|
|
13
13
|
it 'should create correct indexes' do
|
14
14
|
expect(Bar.collection.indexes.get(location: '2d'))
|
15
|
-
.to
|
16
|
-
|
17
|
-
|
15
|
+
.to eq('background' => false,
|
16
|
+
'key' => { 'location' => '2d' },
|
17
|
+
'name' => 'location_2d',
|
18
|
+
'v' => 2)
|
18
19
|
end
|
19
20
|
|
20
21
|
it 'should set spatial fields' do
|
@@ -12,9 +12,11 @@ describe Mongoid::Fields do
|
|
12
12
|
|
13
13
|
it 'should create correct indexes' do
|
14
14
|
expect(Alarm.collection.indexes.get(spot: '2dsphere'))
|
15
|
-
.to include('
|
15
|
+
.to include('2dsphereIndexVersion' => 3,
|
16
|
+
'background' => false,
|
17
|
+
'key' => { 'spot' => '2dsphere' },
|
16
18
|
'name' => 'spot_2dsphere',
|
17
|
-
'
|
19
|
+
'v' => 2)
|
18
20
|
end
|
19
21
|
|
20
22
|
it 'should set spatial fields' do
|
data/spec/mongoid.yml
ADDED
@@ -0,0 +1,298 @@
|
|
1
|
+
development:
|
2
|
+
# Configure available database clients. (required)
|
3
|
+
clients:
|
4
|
+
# Defines the default client. (required)
|
5
|
+
default:
|
6
|
+
# Mongoid can connect to a URI accepted by the driver:
|
7
|
+
# uri: mongodb://user:password@mongodb.domain.com:27017/queroir_development
|
8
|
+
|
9
|
+
# Otherwise define the parameters separately.
|
10
|
+
# This defines the name of the default database that Mongoid can connect to.
|
11
|
+
# (required).
|
12
|
+
database: mongoid_geospatial_dev
|
13
|
+
# Provides the hosts the default client can connect to. Must be an array
|
14
|
+
# of host:port pairs. (required)
|
15
|
+
hosts:
|
16
|
+
- localhost:28017
|
17
|
+
options:
|
18
|
+
# Note that all options listed below are Ruby driver client options (the mongo gem).
|
19
|
+
# Please refer to the driver documentation of the version of the mongo gem you are using
|
20
|
+
# for the most up-to-date list of options.
|
21
|
+
|
22
|
+
# Change the default write concern. (default = { w: 1 })
|
23
|
+
# write:
|
24
|
+
# w: 1
|
25
|
+
|
26
|
+
# Change the default read preference. Valid options for mode are: :secondary,
|
27
|
+
# :secondary_preferred, :primary, :primary_preferred, :nearest
|
28
|
+
# (default: primary)
|
29
|
+
# read:
|
30
|
+
# mode: :secondary_preferred
|
31
|
+
# tag_sets:
|
32
|
+
# - use: web
|
33
|
+
|
34
|
+
# The name of the user for authentication.
|
35
|
+
# user: 'user'
|
36
|
+
|
37
|
+
# The password of the user for authentication.
|
38
|
+
# password: 'password'
|
39
|
+
|
40
|
+
# The user's database roles.
|
41
|
+
# roles:
|
42
|
+
# - 'dbOwner'
|
43
|
+
|
44
|
+
# Change the default authentication mechanism. Valid options include:
|
45
|
+
# :scram, :scram256, :mongodb_cr, :mongodb_x509, :gssapi, :aws, :plain.
|
46
|
+
# MongoDB Server defaults to :scram, which will use "SCRAM-SHA-256" if available,
|
47
|
+
# otherwise fallback to "SCRAM-SHA-1" (:scram256 will always use "SCRAM-SHA-256".)
|
48
|
+
# This setting is handled by the MongoDB Ruby Driver. Please refer to:
|
49
|
+
# https://mongodb.com/docs/ruby-driver/current/reference/authentication/
|
50
|
+
# auth_mech: :scram
|
51
|
+
|
52
|
+
# The database or source to authenticate the user against.
|
53
|
+
# (default: the database specified above or admin)
|
54
|
+
# auth_source: admin
|
55
|
+
|
56
|
+
# Force the driver cluster to behave in a certain manner instead of auto-discovering.
|
57
|
+
# Can be one of: :direct, :replica_set, :sharded. Set to :direct
|
58
|
+
# when connecting to hidden members of a replica set.
|
59
|
+
# connect: :direct
|
60
|
+
|
61
|
+
# Changes the default time in seconds the server monitors refresh their status
|
62
|
+
# via hello commands. (default: 10)
|
63
|
+
# heartbeat_frequency: 10
|
64
|
+
|
65
|
+
# The time in seconds for selecting servers for a near read preference. (default: 0.015)
|
66
|
+
# local_threshold: 0.015
|
67
|
+
|
68
|
+
# The timeout in seconds for selecting a server for an operation. (default: 30)
|
69
|
+
# server_selection_timeout: 30
|
70
|
+
|
71
|
+
# The maximum number of connections in the connection pool. (default: 5)
|
72
|
+
# max_pool_size: 5
|
73
|
+
|
74
|
+
# The minimum number of connections in the connection pool. (default: 1)
|
75
|
+
# min_pool_size: 1
|
76
|
+
|
77
|
+
# The time to wait, in seconds, in the connection pool for a connection
|
78
|
+
# to be checked in before timing out. (default: 5)
|
79
|
+
# wait_queue_timeout: 5
|
80
|
+
|
81
|
+
# The time to wait to establish a connection before timing out, in seconds.
|
82
|
+
# (default: 10)
|
83
|
+
# connect_timeout: 10
|
84
|
+
|
85
|
+
# How long to wait for a response for each operation sent to the
|
86
|
+
# server. This timeout should be set to a value larger than the
|
87
|
+
# processing time for the longest operation that will be executed
|
88
|
+
# by the application. Note that this is a client-side timeout;
|
89
|
+
# the server may continue executing an operation after the client
|
90
|
+
# aborts it with the SocketTimeout exception.
|
91
|
+
# (default: nil, meaning no timeout)
|
92
|
+
# socket_timeout: 5
|
93
|
+
|
94
|
+
# The name of the replica set to connect to. Servers provided as seeds that do
|
95
|
+
# not belong to this replica set will be ignored.
|
96
|
+
# replica_set: name
|
97
|
+
|
98
|
+
# Compressors to use for wire protocol compression. (default is to not use compression)
|
99
|
+
# "zstd" requires zstd-ruby gem. "snappy" requires snappy gem.
|
100
|
+
# Refer to: https://www.mongodb.com/docs/ruby-driver/current/reference/create-client/#compression
|
101
|
+
# compressors: ["zstd", "snappy", "zlib"]
|
102
|
+
|
103
|
+
# Whether to connect to the servers via ssl. (default: false)
|
104
|
+
# ssl: true
|
105
|
+
|
106
|
+
# The certificate file used to identify the connection against MongoDB.
|
107
|
+
# ssl_cert: /path/to/my.cert
|
108
|
+
|
109
|
+
# The private keyfile used to identify the connection against MongoDB.
|
110
|
+
# Note that even if the key is stored in the same file as the certificate,
|
111
|
+
# both need to be explicitly specified.
|
112
|
+
# ssl_key: /path/to/my.key
|
113
|
+
|
114
|
+
# A passphrase for the private key.
|
115
|
+
# ssl_key_pass_phrase: password
|
116
|
+
|
117
|
+
# Whether to do peer certification validation. (default: true)
|
118
|
+
# ssl_verify: true
|
119
|
+
|
120
|
+
# The file containing concatenated certificate authority certificates
|
121
|
+
# used to validate certs passed from the other end of the connection.
|
122
|
+
# ssl_ca_cert: /path/to/ca.cert
|
123
|
+
|
124
|
+
# Whether to truncate long log lines. (default: true)
|
125
|
+
# truncate_logs: true
|
126
|
+
|
127
|
+
# Configure Mongoid-specific options. (optional)
|
128
|
+
options:
|
129
|
+
# Allow BSON::Decimal128 to be parsed and returned directly in
|
130
|
+
# field values. When BSON 5 is present and the this option is set to false
|
131
|
+
# (the default), BSON::Decimal128 values in the database will be returned
|
132
|
+
# as BigDecimal.
|
133
|
+
#
|
134
|
+
# @note this option only has effect when BSON 5+ is present. Otherwise,
|
135
|
+
# the setting is ignored.
|
136
|
+
# allow_bson5_decimal128: false
|
137
|
+
|
138
|
+
# When this flag is false, named scopes cannot unset a default scope.
|
139
|
+
# This is the traditional (and default) behavior in Mongoid 9 and earlier.
|
140
|
+
#
|
141
|
+
# Setting this flag to true will allow named scopes to unset the default
|
142
|
+
# scope. This will be the default in Mongoid 10.
|
143
|
+
#
|
144
|
+
# See https://jira.mongodb.org/browse/MONGOID-5785 for more details.
|
145
|
+
# allow_scopes_to_unset_default_scope: false
|
146
|
+
|
147
|
+
# Application name that is printed to the MongoDB logs upon establishing
|
148
|
+
# a connection. Note that the name cannot exceed 128 bytes in length.
|
149
|
+
# It is also used as the database name if the database name is not
|
150
|
+
# explicitly defined.
|
151
|
+
app_name: mongoid_geospatial
|
152
|
+
|
153
|
+
# When this flag is false, callbacks for embedded documents will not be
|
154
|
+
# called. This is the default in 9.0.
|
155
|
+
#
|
156
|
+
# Setting this flag to true restores the pre-9.0 behavior, where callbacks
|
157
|
+
# for embedded documents are called. This may lead to stack overflow errors
|
158
|
+
# if there are more than cicrca 1000 embedded documents in the root
|
159
|
+
# document's dependencies graph.
|
160
|
+
# See https://jira.mongodb.org/browse/MONGOID-5658 for more details.
|
161
|
+
# around_callbacks_for_embeds: false
|
162
|
+
|
163
|
+
# Sets the async_query_executor for the application. By default the thread pool executor
|
164
|
+
# is set to `:immediate. Options are:
|
165
|
+
#
|
166
|
+
# - :immediate - Initializes a single +Concurrent::ImmediateExecutor+
|
167
|
+
# - :global_thread_pool - Initializes a single +Concurrent::ThreadPoolExecutor+
|
168
|
+
# that uses the +async_query_concurrency+ for the +max_threads+ value.
|
169
|
+
# async_query_executor: :immediate
|
170
|
+
|
171
|
+
# Mark belongs_to associations as required by default, so that saving a
|
172
|
+
# model with a missing belongs_to association will trigger a validation
|
173
|
+
# error.
|
174
|
+
# belongs_to_required_by_default: true
|
175
|
+
|
176
|
+
# Set the global discriminator key.
|
177
|
+
# discriminator_key: "_type"
|
178
|
+
|
179
|
+
# Raise an exception when a field is redefined.
|
180
|
+
# duplicate_fields_exception: false
|
181
|
+
|
182
|
+
# Defines how many asynchronous queries can be executed concurrently.
|
183
|
+
# This option should be set only if `async_query_executor` is set
|
184
|
+
# to `:global_thread_pool`.
|
185
|
+
# global_executor_concurrency: nil
|
186
|
+
|
187
|
+
# When this flag is true, any attempt to change the _id of a persisted
|
188
|
+
# document will raise an exception (`Errors::ImmutableAttribute`).
|
189
|
+
# This is the default in 9.0. Setting this flag to false restores the
|
190
|
+
# pre-9.0 behavior, where changing the _id of a persisted
|
191
|
+
# document might be ignored, or it might work, depending on the situation.
|
192
|
+
# immutable_ids: true
|
193
|
+
|
194
|
+
# Include the root model name in json serialization.
|
195
|
+
# include_root_in_json: false
|
196
|
+
|
197
|
+
# # Include the _type field in serialization.
|
198
|
+
# include_type_for_serialization: false
|
199
|
+
|
200
|
+
# Whether to join nested persistence contexts for atomic operations
|
201
|
+
# to parent contexts by default.
|
202
|
+
# join_contexts: false
|
203
|
+
|
204
|
+
# When this flag is false (the default as of Mongoid 9.0), a document that
|
205
|
+
# is created or loaded will remember the storage options that were active
|
206
|
+
# when it was loaded, and will use those same options by default when
|
207
|
+
# saving or reloading itself.
|
208
|
+
#
|
209
|
+
# When this flag is true you'll get pre-9.0 behavior, where a document will
|
210
|
+
# not remember the storage options from when it was loaded/created, and
|
211
|
+
# subsequent updates will need to explicitly set up those options each time.
|
212
|
+
#
|
213
|
+
# For example:
|
214
|
+
#
|
215
|
+
# record = Model.with(collection: 'other_collection') { Model.first }
|
216
|
+
#
|
217
|
+
# This will try to load the first document from 'other_collection' and
|
218
|
+
# instantiate it as a Model instance. Pre-9.0, the record object would
|
219
|
+
# not remember that it came from 'other_collection', and attempts to
|
220
|
+
# update it or reload it would fail unless you first remembered to
|
221
|
+
# explicitly specify the collection every time.
|
222
|
+
#
|
223
|
+
# As of Mongoid 9.0, the record will remember that it came from
|
224
|
+
# 'other_collection', and updates and reloads will automatically default
|
225
|
+
# to that collection, for that record object.
|
226
|
+
# legacy_persistence_context_behavior: false
|
227
|
+
|
228
|
+
# When this flag is false, a document will become read-only only once the
|
229
|
+
# #readonly! method is called, and an error will be raised on attempting
|
230
|
+
# to save or update such documents, instead of just on delete. When this
|
231
|
+
# flag is true, a document is only read-only if it has been projected
|
232
|
+
# using #only or #without, and read-only documents will not be
|
233
|
+
# deletable/destroyable, but they will be savable/updatable.
|
234
|
+
# When this feature flag is turned on, the read-only state will be reset on
|
235
|
+
# reload, but when it is turned off, it won't be.
|
236
|
+
# legacy_readonly: false
|
237
|
+
|
238
|
+
# The log level.
|
239
|
+
#
|
240
|
+
# It must be set prior to referencing clients or Mongo.logger,
|
241
|
+
# changes to this option are not be propagated to any clients and
|
242
|
+
# loggers that already exist.
|
243
|
+
#
|
244
|
+
# Additionally, only when the clients are configured via the
|
245
|
+
# configuration file is the log level given by this option honored.
|
246
|
+
# log_level: :info
|
247
|
+
|
248
|
+
# Store BigDecimals as Decimal128s instead of strings in the db.
|
249
|
+
# map_big_decimal_to_decimal128: true
|
250
|
+
|
251
|
+
# Preload all models in development, needed when models use inheritance.
|
252
|
+
# preload_models: false
|
253
|
+
|
254
|
+
# When this flag is true, callbacks for every embedded document will be
|
255
|
+
# called only once, even if the embedded document is embedded in multiple
|
256
|
+
# documents in the root document's dependencies graph.
|
257
|
+
# This is the default in 9.0. Setting this flag to false restores the
|
258
|
+
# pre-9.0 behavior, where callbacks are called for every occurrence of an
|
259
|
+
# embedded document. The pre-9.0 behavior leads to a problem that for multi
|
260
|
+
# level nested documents callbacks are called multiple times.
|
261
|
+
# See https://jira.mongodb.org/browse/MONGOID-5542
|
262
|
+
# prevent_multiple_calls_of_embedded_callbacks: true
|
263
|
+
|
264
|
+
# Raise an error when performing a #find and the document is not found.
|
265
|
+
# raise_not_found_error: true
|
266
|
+
|
267
|
+
# Raise an error when defining a scope with the same name as an
|
268
|
+
# existing method.
|
269
|
+
# scope_overwrite_exception: false
|
270
|
+
|
271
|
+
# Return stored times as UTC.
|
272
|
+
use_utc: true
|
273
|
+
|
274
|
+
# Configure Driver-specific options. (optional)
|
275
|
+
driver_options:
|
276
|
+
# When this flag is off, an aggregation done on a view will be executed over
|
277
|
+
# the documents included in that view, instead of all documents in the
|
278
|
+
# collection. When this flag is on, the view fiter is ignored.
|
279
|
+
# broken_view_aggregate: true
|
280
|
+
|
281
|
+
# When this flag is set to false, the view options will be correctly
|
282
|
+
# propagated to readable methods.
|
283
|
+
# broken_view_options: true
|
284
|
+
|
285
|
+
# When this flag is set to true, the update and replace methods will
|
286
|
+
# validate the paramters and raise an error if they are invalid.
|
287
|
+
# validate_update_replace: false
|
288
|
+
|
289
|
+
test:
|
290
|
+
clients:
|
291
|
+
default:
|
292
|
+
database: mongoid_geospatial_test
|
293
|
+
hosts:
|
294
|
+
- localhost:28017
|
295
|
+
options:
|
296
|
+
read:
|
297
|
+
mode: :primary
|
298
|
+
max_pool_size: 1
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# require 'pry'
|
2
1
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
3
|
|
@@ -13,15 +12,16 @@ if ENV['CI']
|
|
13
12
|
end
|
14
13
|
|
15
14
|
require 'rspec'
|
16
|
-
# require 'mongoid'
|
17
|
-
# require "mocha"
|
18
15
|
require 'mongoid/geospatial'
|
19
16
|
|
20
|
-
|
17
|
+
Mongoid.load!(File.expand_path('../mongoid.yml', __FILE__), :test)
|
21
18
|
|
22
|
-
|
23
|
-
|
19
|
+
if ENV['DEBUG'] == 'true'
|
20
|
+
Mongo::Logger.logger.level = Logger::DEBUG
|
21
|
+
else
|
22
|
+
Mongo::Logger.logger.level = Logger::INFO
|
24
23
|
end
|
24
|
+
# Mongo::Logger.logger.level = Logger::DEBUG
|
25
25
|
|
26
26
|
# Autoload every model for the test suite that sits in spec/app/models.
|
27
27
|
Dir[File.join(MODELS, '*.rb')].sort.each do |file|
|
@@ -29,19 +29,14 @@ Dir[File.join(MODELS, '*.rb')].sort.each do |file|
|
|
29
29
|
autoload name.camelize.to_sym, name
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
# Require all support files.
|
33
|
+
Dir[File.join(SUPPORT, '*.rb')].sort.each { |file| require file }
|
33
34
|
|
34
35
|
RSpec.configure do |config|
|
35
|
-
# config.mock_with(:mocha)
|
36
|
-
|
37
36
|
config.before(:each) do
|
38
37
|
Mongoid.purge!
|
39
38
|
Mongoid::Geospatial::Config.reset!
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
43
|
-
Mongo::Logger.logger.level = Logger::INFO if Mongoid::VERSION >= '5'
|
44
|
-
|
45
|
-
# Mongoid.load!(File.expand_path('../support/mongoid.yml', __FILE__), :test)
|
46
|
-
|
47
42
|
puts "Running with Mongoid v#{Mongoid::VERSION}"
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-geospatial
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 7.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Ong
|
8
8
|
- Marcos Piccinini
|
9
|
-
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: mongoid
|
@@ -38,18 +37,15 @@ files:
|
|
38
37
|
- ".hound.yml"
|
39
38
|
- ".rspec"
|
40
39
|
- ".rubocop.yml"
|
41
|
-
- ".rubocop_todo.yml"
|
42
40
|
- ".travis.yml"
|
43
41
|
- CHANGELOG.md
|
44
42
|
- CONTRIBUTING.md
|
45
|
-
- Dangerfile
|
46
43
|
- Gemfile
|
47
44
|
- Guardfile
|
48
45
|
- MIT-LICENSE
|
49
46
|
- README.md
|
50
47
|
- RELEASING.md
|
51
48
|
- Rakefile
|
52
|
-
- bench/bench
|
53
49
|
- lib/mongoid/geospatial.rb
|
54
50
|
- lib/mongoid/geospatial/config.rb
|
55
51
|
- lib/mongoid/geospatial/config/point.rb
|
@@ -67,6 +63,7 @@ files:
|
|
67
63
|
- lib/mongoid/geospatial/wrappers/georuby.rb
|
68
64
|
- lib/mongoid/geospatial/wrappers/rgeo.rb
|
69
65
|
- mongoid-geospatial.gemspec
|
66
|
+
- spec/bench
|
70
67
|
- spec/models/address.rb
|
71
68
|
- spec/models/alarm.rb
|
72
69
|
- spec/models/bar.rb
|
@@ -77,6 +74,7 @@ files:
|
|
77
74
|
- spec/models/phone.rb
|
78
75
|
- spec/models/place.rb
|
79
76
|
- spec/models/river.rb
|
77
|
+
- spec/mongoid.yml
|
80
78
|
- spec/mongoid/geospatial/config_spec.rb
|
81
79
|
- spec/mongoid/geospatial/fields/box_spec.rb
|
82
80
|
- spec/mongoid/geospatial/fields/circle_spec.rb
|
@@ -98,7 +96,6 @@ homepage: https://github.com/mongoid/mongoid-geospatial
|
|
98
96
|
licenses:
|
99
97
|
- MIT
|
100
98
|
metadata: {}
|
101
|
-
post_install_message:
|
102
99
|
rdoc_options: []
|
103
100
|
require_paths:
|
104
101
|
- lib
|
@@ -113,12 +110,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
110
|
- !ruby/object:Gem::Version
|
114
111
|
version: '0'
|
115
112
|
requirements: []
|
116
|
-
|
117
|
-
rubygems_version: 2.7.6
|
118
|
-
signing_key:
|
113
|
+
rubygems_version: 3.6.7
|
119
114
|
specification_version: 4
|
120
115
|
summary: Mongoid Extension that simplifies MongoDB Geospatial Operations.
|
121
116
|
test_files:
|
117
|
+
- spec/bench
|
122
118
|
- spec/models/address.rb
|
123
119
|
- spec/models/alarm.rb
|
124
120
|
- spec/models/bar.rb
|
@@ -129,6 +125,7 @@ test_files:
|
|
129
125
|
- spec/models/phone.rb
|
130
126
|
- spec/models/place.rb
|
131
127
|
- spec/models/river.rb
|
128
|
+
- spec/mongoid.yml
|
132
129
|
- spec/mongoid/geospatial/config_spec.rb
|
133
130
|
- spec/mongoid/geospatial/fields/box_spec.rb
|
134
131
|
- spec/mongoid/geospatial/fields/circle_spec.rb
|
data/.rubocop_todo.yml
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
# This configuration was generated by
|
2
|
-
# `rubocop --auto-gen-config`
|
3
|
-
# on 2018-11-09 16:09:41 -0500 using RuboCop version 0.60.0.
|
4
|
-
# The point is for the user to remove these configuration records
|
5
|
-
# one by one as the offenses are removed from the code base.
|
6
|
-
# Note that changes in the inspected code, or installation of new
|
7
|
-
# versions of RuboCop, may require this file to be generated again.
|
8
|
-
|
9
|
-
# Offense count: 4
|
10
|
-
# Configuration parameters: Include.
|
11
|
-
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
|
12
|
-
Bundler/DuplicatedGem:
|
13
|
-
Exclude:
|
14
|
-
- 'Gemfile'
|
15
|
-
|
16
|
-
# Offense count: 2
|
17
|
-
Lint/DuplicateMethods:
|
18
|
-
Exclude:
|
19
|
-
- 'lib/mongoid/geospatial/fields/circle.rb'
|
20
|
-
|
21
|
-
# Offense count: 3
|
22
|
-
Metrics/AbcSize:
|
23
|
-
Max: 22
|
24
|
-
|
25
|
-
# Offense count: 21
|
26
|
-
# Configuration parameters: CountComments, ExcludedMethods.
|
27
|
-
# ExcludedMethods: refine
|
28
|
-
Metrics/BlockLength:
|
29
|
-
Max: 216
|
30
|
-
|
31
|
-
# Offense count: 1
|
32
|
-
Metrics/CyclomaticComplexity:
|
33
|
-
Max: 7
|
34
|
-
|
35
|
-
# Offense count: 1
|
36
|
-
# Configuration parameters: CountComments, ExcludedMethods.
|
37
|
-
Metrics/MethodLength:
|
38
|
-
Max: 11
|
39
|
-
|
40
|
-
# Offense count: 1
|
41
|
-
Naming/AccessorMethodName:
|
42
|
-
Exclude:
|
43
|
-
- 'spec/models/address.rb'
|
44
|
-
|
45
|
-
# Offense count: 9
|
46
|
-
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
|
47
|
-
# AllowedNames: io, id, to, by, on, in, at, ip, db
|
48
|
-
Naming/UncommunicativeMethodParamName:
|
49
|
-
Exclude:
|
50
|
-
- 'lib/mongoid/geospatial/fields/point.rb'
|
51
|
-
- 'lib/mongoid/geospatial/geometry_field.rb'
|
52
|
-
|
53
|
-
# Offense count: 3
|
54
|
-
Style/ClassVars:
|
55
|
-
Exclude:
|
56
|
-
- 'lib/mongoid/geospatial.rb'
|
57
|
-
|
58
|
-
# Offense count: 4
|
59
|
-
Style/CommentedKeyword:
|
60
|
-
Exclude:
|
61
|
-
- 'lib/mongoid/geospatial/fields/point.rb'
|
62
|
-
|
63
|
-
# Offense count: 6
|
64
|
-
Style/Documentation:
|
65
|
-
Exclude:
|
66
|
-
- 'spec/**/*'
|
67
|
-
- 'test/**/*'
|
68
|
-
- 'bench/bench'
|
69
|
-
- 'lib/mongoid/geospatial/config.rb'
|
70
|
-
- 'lib/mongoid/geospatial/config/point.rb'
|
71
|
-
|
72
|
-
# Offense count: 2
|
73
|
-
# Cop supports --auto-correct.
|
74
|
-
# Configuration parameters: EnforcedStyle.
|
75
|
-
# SupportedStyles: module_function, extend_self
|
76
|
-
Style/ModuleFunction:
|
77
|
-
Exclude:
|
78
|
-
- 'lib/mongoid/geospatial/config.rb'
|
79
|
-
- 'lib/mongoid/geospatial/config/point.rb'
|
80
|
-
|
81
|
-
# Offense count: 4
|
82
|
-
# Cop supports --auto-correct.
|
83
|
-
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
|
84
|
-
# SupportedStyles: slashes, percent_r, mixed
|
85
|
-
Style/RegexpLiteral:
|
86
|
-
Exclude:
|
87
|
-
- 'Guardfile'
|
88
|
-
|
89
|
-
# Offense count: 15
|
90
|
-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
91
|
-
# URISchemes: http, https
|
92
|
-
Metrics/LineLength:
|
93
|
-
Max: 113
|
data/Dangerfile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
danger.import_dangerfile(gem: 'mongoid-danger')
|