mongoid-geospatial 7.0.0 → 7.1.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/README.md +61 -30
- data/lib/mongoid/geospatial/config/point.rb +5 -2
- data/lib/mongoid/geospatial/config.rb +2 -0
- data/lib/mongoid/geospatial/ext/rgeo_spherical_point_impl.rb +2 -0
- data/lib/mongoid/geospatial/fields/box.rb +2 -0
- data/lib/mongoid/geospatial/fields/circle.rb +2 -2
- data/lib/mongoid/geospatial/fields/line_string.rb +2 -0
- data/lib/mongoid/geospatial/fields/point.rb +18 -15
- data/lib/mongoid/geospatial/fields/polygon.rb +2 -0
- data/lib/mongoid/geospatial/geometry_field.rb +4 -2
- data/lib/mongoid/geospatial/helpers/delegate.rb +2 -0
- data/lib/mongoid/geospatial/helpers/spatial.rb +2 -0
- data/lib/mongoid/geospatial/helpers/sphere.rb +2 -0
- data/lib/mongoid/geospatial/version.rb +3 -1
- data/lib/mongoid/geospatial/wrappers/georuby.rb +2 -0
- data/lib/mongoid/geospatial/wrappers/rgeo.rb +2 -0
- data/lib/mongoid/geospatial.rb +144 -12
- metadata +5 -75
- data/.coveralls.yml +0 -1
- data/.gitignore +0 -49
- data/.hound.yml +0 -2
- data/.rspec +0 -3
- data/.rubocop.yml +0 -8
- data/.travis.yml +0 -33
- data/CHANGELOG.md +0 -23
- data/CONTRIBUTING.md +0 -118
- data/Gemfile +0 -17
- data/Guardfile +0 -16
- data/RELEASING.md +0 -62
- data/Rakefile +0 -20
- data/mongoid-geospatial.gemspec +0 -18
- data/spec/bench +0 -64
- data/spec/models/address.rb +0 -69
- data/spec/models/alarm.rb +0 -12
- data/spec/models/bar.rb +0 -14
- data/spec/models/bus.rb +0 -12
- data/spec/models/event.rb +0 -18
- data/spec/models/farm.rb +0 -13
- data/spec/models/person.rb +0 -91
- data/spec/models/phone.rb +0 -8
- data/spec/models/place.rb +0 -13
- data/spec/models/river.rb +0 -22
- data/spec/mongoid/geospatial/config_spec.rb +0 -22
- data/spec/mongoid/geospatial/fields/box_spec.rb +0 -8
- data/spec/mongoid/geospatial/fields/circle_spec.rb +0 -8
- data/spec/mongoid/geospatial/fields/line_string_spec.rb +0 -78
- data/spec/mongoid/geospatial/fields/point_spec.rb +0 -296
- data/spec/mongoid/geospatial/fields/polygon_spec.rb +0 -87
- data/spec/mongoid/geospatial/geospatial_spec.rb +0 -222
- data/spec/mongoid/geospatial/helpers/core_spec.rb +0 -35
- data/spec/mongoid/geospatial/helpers/delegate_spec.rb +0 -67
- data/spec/mongoid/geospatial/helpers/spatial_spec.rb +0 -40
- data/spec/mongoid/geospatial/helpers/sphere_spec.rb +0 -31
- data/spec/mongoid/geospatial/wrappers/georuby_spec.rb +0 -63
- data/spec/mongoid/geospatial/wrappers/rgeo_spec.rb +0 -115
- data/spec/mongoid.yml +0 -298
- data/spec/spec_helper.rb +0 -42
- data/spec/support/authentication.rb +0 -28
- data/spec/support/mongod.conf +0 -3
- data/spec/support/mongoid.yml +0 -19
data/.gitignore
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
Gemfile.lock
|
2
|
-
# rcov generated
|
3
|
-
coverage
|
4
|
-
|
5
|
-
# rdoc generated
|
6
|
-
rdoc
|
7
|
-
|
8
|
-
# yard generated
|
9
|
-
doc
|
10
|
-
.yardoc
|
11
|
-
|
12
|
-
# bundler
|
13
|
-
.bundle
|
14
|
-
|
15
|
-
# jeweler generated
|
16
|
-
pkg
|
17
|
-
|
18
|
-
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
19
|
-
#
|
20
|
-
# * Create a file at ~/.gitignore
|
21
|
-
# * Include files you want ignored
|
22
|
-
# * Run: git config --global core.excludesfile ~/.gitignore
|
23
|
-
#
|
24
|
-
# After doing this, these files will be ignored in all your git projects,
|
25
|
-
# saving you from having to 'pollute' every project you touch with them
|
26
|
-
#
|
27
|
-
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
28
|
-
#
|
29
|
-
# For MacOS:
|
30
|
-
#
|
31
|
-
.DS_Store
|
32
|
-
|
33
|
-
# For TextMate
|
34
|
-
#*.tmproj
|
35
|
-
#tmtags
|
36
|
-
|
37
|
-
# For emacs:
|
38
|
-
#*~
|
39
|
-
#\#*
|
40
|
-
#.\#*
|
41
|
-
|
42
|
-
# For vim:
|
43
|
-
*.swp
|
44
|
-
|
45
|
-
# For redcar:
|
46
|
-
#.redcar
|
47
|
-
|
48
|
-
# For rubinius:
|
49
|
-
#*.rbc
|
data/.hound.yml
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
data/.travis.yml
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
sudo: false
|
2
|
-
|
3
|
-
language: ruby
|
4
|
-
|
5
|
-
cache: bundler
|
6
|
-
|
7
|
-
services: mongodb
|
8
|
-
|
9
|
-
rvm:
|
10
|
-
- 2.5.3
|
11
|
-
|
12
|
-
before_install:
|
13
|
-
- gem update bundler
|
14
|
-
|
15
|
-
before_script:
|
16
|
-
- bundle exec danger
|
17
|
-
|
18
|
-
addons:
|
19
|
-
apt:
|
20
|
-
sources:
|
21
|
-
- mongodb-3.2-precise
|
22
|
-
packages:
|
23
|
-
- mongodb-org-server
|
24
|
-
|
25
|
-
env:
|
26
|
-
- MONGOID_VERSION=5
|
27
|
-
- MONGOID_VERSION=6
|
28
|
-
- MONGOID_VERSION=7
|
29
|
-
- MONGOID_VERSION=HEAD
|
30
|
-
|
31
|
-
matrix:
|
32
|
-
allow_failures:
|
33
|
-
- env: MONGOID_VERSION=HEAD
|
data/CHANGELOG.md
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
## 5.1.1 (Next)
|
2
|
-
|
3
|
-
* Your contribution here.
|
4
|
-
|
5
|
-
## 5.1.0 (2018/11/09)
|
6
|
-
|
7
|
-
* [#61](https://github.com/mongoid/mongoid-geospatial/pull/64): Add global configuration for switching between LngLat and LatLng - [@dblock](https://github.com/dblock).
|
8
|
-
* [#59](https://github.com/mongoid/mongoid-geospatial/pull/59), [#65](https://github.com/mongoid/mongoid-geospatial/pull/65): Test against Mongoid 5, 6 and 7 - [@dblock](https://github.com/dblock).
|
9
|
-
* [#52](https://github.com/mongoid/mongoid-geospatial/pull/52), [#70](https://github.com/mongoid/mongoid-geospatial/pull/70): Added Danger and Rubocop, PR and code linters - [@dblock](https://github.com/dblock).
|
10
|
-
|
11
|
-
## 5.0.0 (2015/07/23)
|
12
|
-
|
13
|
-
* Mongoid 5 support - [@nofxx](https://github.com/nofxx).
|
14
|
-
|
15
|
-
## 4.0.1 (2015/03/04)
|
16
|
-
|
17
|
-
## 4.0.0 (2015/01/11)
|
18
|
-
|
19
|
-
* Mongoid 4 support - [@nofxx](https://github.com/nofxx).
|
20
|
-
|
21
|
-
## 3.9.0 (2014/12/22)
|
22
|
-
|
23
|
-
* Initial public release - [@nofxx](https://github.com/nofxx).
|
data/CONTRIBUTING.md
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
Contributing to Mongoid::Geospatial
|
2
|
-
===================================
|
3
|
-
|
4
|
-
Mongoid::Geospatial is work of [many of contributors](https://github.com/mongoid/mongoid-geospatial/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/mongoid/mongoid-geospatial/pulls), [propose features, ask questions and discuss issues](https://github.com/mongoid/mongoid-geospatial/issues).
|
5
|
-
|
6
|
-
#### Fork the Project
|
7
|
-
|
8
|
-
Fork the [project on Github](https://github.com/mongoid/mongoid-geospatial) and check out your copy.
|
9
|
-
|
10
|
-
```
|
11
|
-
git clone https://github.com/contributor/mongoid-geospatial.git
|
12
|
-
cd mongoid-geospatial
|
13
|
-
git remote add upstream https://github.com/mongoid/mongoid-geospatial.git
|
14
|
-
```
|
15
|
-
|
16
|
-
#### Create a Topic Branch
|
17
|
-
|
18
|
-
Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
|
19
|
-
|
20
|
-
```
|
21
|
-
git checkout master
|
22
|
-
git pull upstream master
|
23
|
-
git checkout -b my-feature-branch
|
24
|
-
```
|
25
|
-
|
26
|
-
#### Bundle Install and Test
|
27
|
-
|
28
|
-
Ensure that you can build the project and run tests.
|
29
|
-
|
30
|
-
```
|
31
|
-
bundle install
|
32
|
-
bundle exec rake
|
33
|
-
```
|
34
|
-
|
35
|
-
#### Write Tests
|
36
|
-
|
37
|
-
Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add to [spec/mongoid-geospatial](spec/mongoid-geospatial).
|
38
|
-
|
39
|
-
We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
|
40
|
-
|
41
|
-
#### Write Code
|
42
|
-
|
43
|
-
Implement your feature or bug fix.
|
44
|
-
|
45
|
-
Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop), run `bundle exec rubocop` and fix any style issues highlighted.
|
46
|
-
|
47
|
-
Make sure that `bundle exec rake` completes without errors.
|
48
|
-
|
49
|
-
#### Write Documentation
|
50
|
-
|
51
|
-
Document any external behavior in the [README](README.md).
|
52
|
-
|
53
|
-
#### Update Changelog
|
54
|
-
|
55
|
-
Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*. Make it look like every other line, including your name and link to your Github account.
|
56
|
-
|
57
|
-
#### Commit Changes
|
58
|
-
|
59
|
-
Make sure git knows your name and email address:
|
60
|
-
|
61
|
-
```
|
62
|
-
git config --global user.name "Your Name"
|
63
|
-
git config --global user.email "contributor@example.com"
|
64
|
-
```
|
65
|
-
|
66
|
-
Writing good commit logs is important. A commit log should describe what changed and why.
|
67
|
-
|
68
|
-
```
|
69
|
-
git add ...
|
70
|
-
git commit
|
71
|
-
```
|
72
|
-
|
73
|
-
#### Push
|
74
|
-
|
75
|
-
```
|
76
|
-
git push origin my-feature-branch
|
77
|
-
```
|
78
|
-
|
79
|
-
#### Make a Pull Request
|
80
|
-
|
81
|
-
Go to https://github.com/contributor/mongoid-geospatial and select your feature branch. Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
|
82
|
-
|
83
|
-
#### Rebase
|
84
|
-
|
85
|
-
If you've been working on a change for a while, rebase with upstream/master.
|
86
|
-
|
87
|
-
```
|
88
|
-
git fetch upstream
|
89
|
-
git rebase upstream/master
|
90
|
-
git push origin my-feature-branch -f
|
91
|
-
```
|
92
|
-
|
93
|
-
#### Update CHANGELOG Again
|
94
|
-
|
95
|
-
Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
|
96
|
-
|
97
|
-
```
|
98
|
-
* [#123](https://github.com/mongoid/mongoid-geospatial/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
|
99
|
-
```
|
100
|
-
|
101
|
-
Amend your previous commit and force push the changes.
|
102
|
-
|
103
|
-
```
|
104
|
-
git commit --amend
|
105
|
-
git push origin my-feature-branch -f
|
106
|
-
```
|
107
|
-
|
108
|
-
#### Check on Your Pull Request
|
109
|
-
|
110
|
-
Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
|
111
|
-
|
112
|
-
#### Be Patient
|
113
|
-
|
114
|
-
It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there!
|
115
|
-
|
116
|
-
#### Thank You
|
117
|
-
|
118
|
-
Please do know that we really appreciate and value your time and work. We love you, really.
|
data/Gemfile
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gem 'mongoid'
|
4
|
-
|
5
|
-
gemspec
|
6
|
-
|
7
|
-
group :development, :test do
|
8
|
-
gem 'fuubar'
|
9
|
-
gem 'rake'
|
10
|
-
gem 'guard'
|
11
|
-
gem 'guard-rspec'
|
12
|
-
gem 'rubocop'
|
13
|
-
end
|
14
|
-
|
15
|
-
group :test do
|
16
|
-
gem 'coveralls', require: false if ENV['CI']
|
17
|
-
end
|
data/Guardfile
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Mongoid Geospatial Guardfile
|
3
|
-
#
|
4
|
-
ignore(/\/.#.+/)
|
5
|
-
|
6
|
-
# notification :off
|
7
|
-
|
8
|
-
guard :rubocop, all_on_start: false, keep_failed: false, notification: false, cli: ['--format', 'emacs'] do
|
9
|
-
watch(/^lib\/(.+)\.rb$/)
|
10
|
-
end
|
11
|
-
|
12
|
-
guard :rspec, cmd: 'bundle exec rspec', notification: true do
|
13
|
-
watch(/^spec\/.+_spec\.rb$/)
|
14
|
-
watch(/^lib\/(.+)\.rb$/) { |m| "spec/#{m[1]}_spec.rb" }
|
15
|
-
watch('spec/spec_helper.rb') { 'spec' }
|
16
|
-
end
|
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'
|
data/mongoid-geospatial.gemspec
DELETED
@@ -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
|
data/spec/models/address.rb
DELETED
@@ -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
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
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
|
data/spec/models/person.rb
DELETED
@@ -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
|