mongoid-geospatial 3.9.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93a8802d5a645b356af69d76585004ed4e080a16
4
- data.tar.gz: 0ec2e2b4b87d28bf04af6d2ed0ef7d1ff49aa412
3
+ metadata.gz: 863dde3c031d08ba8c4a11aaf0708da5ab9e5a86
4
+ data.tar.gz: a0355bef1d9eaa010f880dd7556208ab4bc0aacb
5
5
  SHA512:
6
- metadata.gz: 5142eaf9e0aed0a78e2eb581b7d23b14c50b7050baf030f2e23d66aa9b50806a60ebd87b692f1cb9ba2790a5b8b6aa128480980e2efa3c43fce0d38709493032
7
- data.tar.gz: 1e678afee79c30fd9965c7773d7cb2673f2c0a44d3a23a66cac69082b12cb86e914048a54f438f02322d32d22c3f7273f0893fa4a0d414bad59e4a8f4977d58b
6
+ metadata.gz: a058a1e3350787f81ccedd4179b46708fa5c3edb59a7b83ed4a3d9a8d67c86810d75c0b5ce062d87ab0c33e8dbb6ae290af913d82b15e5067a9321e2a415d799
7
+ data.tar.gz: 52ae29a334d47ec9f011ee0afc30adf2e31bac9d78dcf126a509be035eb0eebf8a7078c4805584a51335102ee567a53b486debff427cbd69f6c2a176dc0dfce2
@@ -3,17 +3,23 @@ bundler_args: --without development
3
3
  rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
+ - 2.1.0
7
+ - 2.2.0
6
8
  - ruby-head
7
- - rbx-19mode
8
9
  - jruby
9
10
  - jruby-head
11
+ - rbx-2
12
+
10
13
  jdk:
11
14
  - oraclejdk7
12
15
  - openjdk7
16
+
13
17
  env: JRUBY_OPTS="--server -Xcompile.invokedynamic=false -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify -J-Xms512m -J-Xmx1024m"
18
+
14
19
  matrix:
15
20
  allow_failures:
16
21
  - rvm: ruby-head
17
22
  - rvm: jruby-head
23
+
18
24
  services:
19
25
  - mongodb
data/Gemfile CHANGED
@@ -1,30 +1,24 @@
1
1
  source 'http://rubygems.org'
2
+
2
3
  gemspec # Specify gem's dependencies in mongoid_geospatial.gemspec
3
4
 
5
+ gem 'pry'
4
6
  gem 'rake'
7
+ gem 'yard'
5
8
  gem 'mongoid' #, github: 'mongoid/mongoid'
6
9
 
7
- group :development do
8
- gem 'pry'
9
- gem 'yard'
10
- end
10
+ gem 'nokogiri'
11
+ gem 'dbf'
12
+ gem 'rgeo'
13
+ gem 'georuby'
11
14
 
12
- group :test do
13
- gem 'dbf'
15
+ if ENV['CI']
16
+ gem 'coveralls', require: false
17
+ else
14
18
  gem 'rspec'
15
- gem 'nokogiri'
16
- gem 'rgeo'
17
- gem 'georuby'
18
-
19
- if ENV['CI']
20
- gem 'coveralls', require: false
21
- gem 'yard'
22
- else
23
- gem 'rubocop'
24
- gem 'fuubar'
25
- gem 'guard'
26
- gem 'guard-rubocop'
27
- gem 'guard-rspec'
28
- # gem 'rb-fsevent'
29
- end
19
+ gem 'rubocop'
20
+ gem 'fuubar'
21
+ gem 'guard'
22
+ gem 'guard-rubocop'
23
+ gem 'guard-rspec'
30
24
  end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2013 Mongoid Geospatial Authors
1
+ Copyright (c) 2009-2015 Mongoid Geospatial Authors
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -11,6 +11,13 @@ Removing some trash, improving and adding support for RGeo and GeoRuby.
11
11
  Version 3+ is going to be beta testing, when it's ready I'll release v4,
12
12
  So the major version stays the same as mongoid.
13
13
 
14
+ ** Gem name: 'mongoid-geospatial' (notice the hyphen) **
15
+
16
+ The name of this gem has changed.
17
+ Please change the underscore to a hyphen.
18
+ If you need to: require 'mongoid/geospatial'
19
+
20
+
14
21
  [![Gem Version](https://badge.fury.io/rb/mongoid-geospatial.png)](http://badge.fury.io/rb/mongoid-geospatial)
15
22
  [![Code Climate](https://codeclimate.com/github/nofxx/mongoid-geospatial.png)](https://codeclimate.com/github/nofxx/mongoid-geospatial)
16
23
  [![Coverage Status](https://coveralls.io/repos/nofxx/mongoid-geospatial/badge.png)](https://coveralls.io/r/nofxx/mongoid-geospatial)
@@ -514,6 +521,3 @@ Contributing
514
521
  * Commit and push until you are happy with your contribution
515
522
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
516
523
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
517
-
518
-
519
- [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/nofxx/mongoid-geospatial/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Just for fun
4
+ #
5
+ $: << File.expand_path("../../lib", __FILE__)
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, cafes = [], []
40
+ b.report("#{t} W NoGeo") do
41
+ t.times { nogeo << NoGeo.create(name: 'Boring').id }
42
+ end
43
+ b.report("#{t} W Rider") { t.times { Rider.create(name: 'Munro') } }
44
+
45
+ b.report("#{t} W Cafe ") do
46
+ t.times { cafes << Cafe.create(name: 'Bacco', spot: [3,3]).id }
47
+ end
48
+ # puts "---"
49
+ b.report("#{t} R NoGeo") { nogeo.each { |id| NoGeo.find(id) }}
50
+ # b.report("#{t} R Rider") { t.times { Rider.create(name: 'Munro') } }
51
+ b.report("#{t} R Cafe ") { cafes.each { |id| Cafe.find(id) }}
52
+ b.report("#{t} R Cafe Georuby") { cafes.each { |id| Cafe.find(id).spot.to_geo }}
53
+ b.report("#{t} R Cafe RGeo") { cafes.each { |id| Cafe.find(id).spot.to_rgeo }}
54
+ end
55
+ b.report("R Cafe GeoRuby") do
56
+ cafe = Cafe.first
57
+ 1_000_000.times { cafe.spot.to_geo }
58
+ end
59
+ b.report("R Cafe RGeo") do
60
+ cafe = Cafe.first
61
+ 1_000_000.times { cafe.spot.to_rgeo }
62
+ end
63
+ end
@@ -1,13 +1,13 @@
1
1
  require 'mongoid'
2
- require 'active_support/core_ext/string/inflections'
3
- require 'active_support/concern'
2
+ # require 'active_support/core_ext/string/inflections'
3
+ # require 'active_support/concern'
4
4
  require 'mongoid/geospatial/helpers/spatial'
5
5
  require 'mongoid/geospatial/helpers/sphere'
6
6
  require 'mongoid/geospatial/helpers/delegate'
7
7
 
8
8
  require 'mongoid/geospatial/fields/geometry_field'
9
9
 
10
- %w(point circle box line polygon).each do |type|
10
+ %w(point circle line box polygon).each do |type|
11
11
  require "mongoid/geospatial/fields/#{type}"
12
12
  end
13
13
 
@@ -20,16 +20,17 @@ module Mongoid
20
20
  module Geospatial
21
21
  extend ActiveSupport::Concern
22
22
 
23
- LNG_SYMBOLS = [:x, :lon, :long, :lng, :longitude, 'x', 'lon', 'long', 'longitude']
23
+ LNG_SYMBOLS = [:x, :lon, :long, :lng, :longitude,
24
+ 'x', 'lon', 'long', 'lng', 'longitude']
24
25
  LAT_SYMBOLS = [:y, :lat, :latitude, 'y', 'lat', 'latitude']
25
26
 
26
27
  EARTH_RADIUS_KM = 6371 # taken directly from mongodb
27
28
  RAD_PER_DEG = Math::PI / 180
28
29
 
29
30
  EARTH_RADIUS = {
31
+ m: EARTH_RADIUS_KM * 1000,
30
32
  km: EARTH_RADIUS_KM,
31
- m: EARTH_RADIUS_KM * 1000,
32
- mi: EARTH_RADIUS_KM * 0.621371192, # taken directly from mongodb
33
+ mi: EARTH_RADIUS_KM * 0.621371192,
33
34
  ft: EARTH_RADIUS_KM * 5280 * 0.621371192,
34
35
  sm: EARTH_RADIUS_KM * 0.53995680345572 # sea mile
35
36
  }
@@ -60,7 +61,8 @@ module Mongoid
60
61
 
61
62
  module ClassMethods #:nodoc:
62
63
  def geo_field(name, options = {})
63
- field name, { type: Mongoid::Geospatial::Point, spatial: true }.merge(options)
64
+ field name, { type: Mongoid::Geospatial::Point,
65
+ spatial: true }.merge(options)
64
66
  end
65
67
 
66
68
  # create spatial index for given field
@@ -88,19 +90,3 @@ module Mongoid
88
90
  end
89
91
  end
90
92
  end
91
-
92
- # model.instance_eval do # wont work
93
- # # define_method "near_#{field.name}" do |*args|
94
- # # self.where(field.name => args)
95
- # # end
96
- # end
97
-
98
- # define_method "near_#{field.name}" do |*args|
99
- # queryable.where(field.near_sphere => args)
100
- # end
101
-
102
- # model.class_eval do
103
- # define_method "close_to" do |*args|
104
- # queriable.where(field.name.near_sphere => *args)
105
- # end
106
- # end
@@ -6,8 +6,7 @@ module Mongoid
6
6
  include Enumerable
7
7
  attr_reader :x, :y
8
8
 
9
- def initialize(x = nil, y = nil)
10
- return unless x && y
9
+ def initialize(x, y)
11
10
  @x, @y = x, y
12
11
  end
13
12
 
@@ -9,7 +9,6 @@ Mongoid::Fields.option :delegate do |model, field, options|
9
9
  y_meth = options[:y] || :y
10
10
 
11
11
  model.instance_eval do
12
-
13
12
  define_method x_meth do
14
13
  self[field.name][0]
15
14
  end
@@ -25,6 +24,5 @@ Mongoid::Fields.option :delegate do |model, field, options|
25
24
  define_method "#{y_meth}=" do |arg|
26
25
  self[field.name][1] = arg
27
26
  end
28
-
29
27
  end
30
28
  end
@@ -7,13 +7,10 @@ Mongoid::Fields.option :spatial do |model, field, _options|
7
7
  # options = {} unless options.kind_of?(Hash)
8
8
 
9
9
  model.class_eval do
10
-
11
10
  spatial_fields << field.name.to_sym
12
11
  spatial_fields_indexed << field.name.to_sym
13
12
 
14
13
  # Create 2D index
15
14
  spatial_index field.name
16
-
17
15
  end
18
-
19
16
  end
@@ -7,12 +7,10 @@ Mongoid::Fields.option :sphere do |model, field, _options|
7
7
  # options = {} unless options.kind_of?(Hash)
8
8
 
9
9
  model.class_eval do
10
-
11
10
  spatial_fields << field.name.to_sym
12
11
  spatial_fields_indexed << field.name.to_sym
13
12
 
14
13
  # Create 2Dsphere index
15
14
  sphere_index field.name
16
-
17
15
  end
18
16
  end
@@ -1,6 +1,6 @@
1
1
  module Mongoid
2
2
  # Gem version
3
3
  module Geospatial
4
- VERSION = '3.9.0'
4
+ VERSION = '4.0.0'
5
5
  end
6
6
  end
@@ -4,7 +4,7 @@ module Mongoid
4
4
  module Geospatial
5
5
  # Wrapper to GeoRuby's Point
6
6
  class Point
7
- delegate :distance, to: :to_geo
7
+ # delegate :distance, to: :to_geo
8
8
 
9
9
  def to_geo
10
10
  return unless valid?
@@ -1,5 +1,5 @@
1
1
  require 'rgeo'
2
- require 'mongoid_geospatial/ext/rgeo_spherical_point_impl'
2
+ require 'mongoid/geospatial/ext/rgeo_spherical_point_impl'
3
3
 
4
4
  module Mongoid
5
5
  module Geospatial
@@ -9,7 +9,8 @@ class Event
9
9
  field :location, type: Point, delegate: true, default: [7, 7]
10
10
 
11
11
  def self.each_day(start_date, end_date)
12
- groups = only(:date).asc(:date).where(:date.gte => start_date, :date.lte => end_date).group
12
+ groups = only(:date).asc(:date)
13
+ .where(:date.gte => start_date, :date.lte => end_date).group
13
14
  groups.each do |hash|
14
15
  yield(hash['date'], hash['group'])
15
16
  end
@@ -3,14 +3,14 @@ class River
3
3
  include Mongoid::Document
4
4
  include Mongoid::Geospatial
5
5
 
6
- field :name, type: String
7
- field :length, type: Integer
8
- field :discharge, type: Integer
9
- field :course, type: Line, spatial: true
6
+ field :name, type: String
7
+ field :length, type: Integer
8
+ field :discharge, type: Integer
9
+ field :course, type: Line, spatial: true
10
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 }
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
@@ -1,10 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongoid::Geospatial::Box do
4
-
5
4
  it 'should work' do
6
5
  alarm = Alarm.new(area: [[1, 2], [3, 4]])
7
6
  expect(alarm.area).to be_a Mongoid::Geospatial::Box
8
7
  end
9
-
10
8
  end
@@ -1,10 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongoid::Geospatial::Circle do
4
-
5
4
  it 'should work' do
6
5
  alarm = Alarm.new(radius: [[1, 2], 3])
7
6
  expect(alarm.radius).to be_a Mongoid::Geospatial::Circle
8
7
  end
9
-
10
8
  end
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongoid::Geospatial::Line do
4
-
5
4
  describe '(de)mongoize' do
6
-
7
5
  it 'should support a field mapped as linestring' do
8
6
  river = River.new(course: [[5, 5], [6, 5], [6, 6], [5, 6]])
9
7
  expect(river.course).to be_a Mongoid::Geospatial::Line
@@ -34,7 +32,5 @@ describe Mongoid::Geospatial::Line do
34
32
  geom = Mongoid::Geospatial::Line.new [[1, 1], [1, 1], [9, 9], [9, 9]]
35
33
  expect(geom.radius_sphere(10)[1]).to be_within(0.001).of(0.001569)
36
34
  end
37
-
38
35
  end
39
-
40
36
  end
@@ -1,40 +1,37 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongoid::Geospatial::Point do
4
+ describe "Moe's Bar" do
5
+ let(:bar) { Bar.create!(name: "Moe's") }
4
6
 
5
- it 'should not interfer with mongoid' do
6
- Bar.create!(name: "Moe's")
7
- expect(Bar.count).to eql(1)
8
- end
7
+ it 'should not interfer with mongoid' do
8
+ expect(bar.class.count).to eql(1)
9
+ end
9
10
 
10
- it 'should not fail if point is nil' do
11
- bar = Bar.create!(name: "Moe's")
12
- expect(bar.location).to be_nil
13
- end
11
+ it 'should not fail if point is nil' do
12
+ expect(bar.location).to be_nil
13
+ end
14
14
 
15
- it 'should set point methodically' do
16
- bar = Bar.create!(name: "Moe's", location: Mongoid::Geospatial::Point.new)
17
- bar.location = Mongoid::Geospatial::Point.new(8, 8)
18
- expect(bar.save).to be_truthy
19
- expect(Bar.first.location.x).to eq(8)
20
- end
15
+ it 'should set point methodically' do
16
+ bar.location = Mongoid::Geospatial::Point.new(8, 8)
17
+ expect(bar.save).to be_truthy
18
+ expect(Bar.first.location.x).to eq(8)
19
+ end
21
20
 
22
- it 'should set point with comma separated text' do
23
- bar = Bar.create!(name: "Moe's", location: Mongoid::Geospatial::Point.new)
24
- bar.location = '2.99,3.99'
25
- expect(bar.location.mongoize).to eq([2.99, 3.99])
26
- end
21
+ it 'should set point with comma separated text' do
22
+ bar.location = '2.99,3.99'
23
+ expect(bar.location.mongoize).to eq([2.99, 3.99])
24
+ end
27
25
 
28
- it 'should set point with space separated text' do
29
- bar = Bar.create!(name: "Moe's", location: Mongoid::Geospatial::Point.new)
30
- bar.location = '2.99 3.99'
31
- expect(bar.location.mongoize).to eq([2.99, 3.99])
32
- end
26
+ it 'should set point with space separated text' do
27
+ bar.location = '2.99 3.99'
28
+ expect(bar.location.mongoize).to eq([2.99, 3.99])
29
+ end
33
30
 
34
- it 'should set point with space comma separated text' do
35
- bar = Bar.create!(name: "Moe's", location: Mongoid::Geospatial::Point.new)
36
- bar.location = '2.99 , 3.99'
37
- expect(bar.location.mongoize).to eq([2.99, 3.99])
31
+ it 'should set point with space comma separated text' do
32
+ bar.location = '2.99 , 3.99'
33
+ expect(bar.location.mongoize).to eq([2.99, 3.99])
34
+ end
38
35
  end
39
36
 
40
37
  it 'should set point to nil' do
@@ -62,7 +59,6 @@ describe Mongoid::Geospatial::Point do
62
59
  end
63
60
 
64
61
  describe 'methods' do
65
-
66
62
  let(:bar) { Bar.create!(location: [3, 2]) }
67
63
 
68
64
  it 'should have a .to_a' do
@@ -92,17 +88,14 @@ describe Mongoid::Geospatial::Point do
92
88
  it 'should have a radius sphere helper in miles' do
93
89
  expect(bar.location.radius_sphere(1, :mi)[1]).to be_within(0.0001).of(0.00025)
94
90
  end
95
-
96
91
  end
97
92
 
98
93
  describe 'queryable' do
99
-
100
94
  before do
101
95
  Bar.create_indexes
102
96
  end
103
97
 
104
98
  describe ':near :near_sphere' do
105
-
106
99
  let!(:berlin) do
107
100
  Bar.create(name: :berlin, location: [52.30, 13.25])
108
101
  end
@@ -131,13 +124,13 @@ describe Mongoid::Geospatial::Point do
131
124
 
132
125
  it 'returns the documents sorted closest to furthest sphere' do
133
126
  person = Person.new(location: [41.23, 2.9])
134
- expect(Bar.near_sphere(location: jim.location))
127
+ expect(Bar.near_sphere(location: person.location))
135
128
  .to eq([paris, prague, berlin])
136
129
  end
137
130
 
138
131
  it 'returns the documents sorted closest to furthest sphere' do
139
132
  person = Person.new(location: [41.23, 2.9])
140
- expect(Bar.where(:location.near_sphere => jim.location))
133
+ expect(Bar.where(:location.near_sphere => person.location))
141
134
  .to eq([paris, prague, berlin])
142
135
  end
143
136
 
@@ -145,7 +138,6 @@ describe Mongoid::Geospatial::Point do
145
138
  expect(Bar.near(location: jim.location).max_distance(location: 10).to_a)
146
139
  .to eq([paris]) # , prague, berlin ]
147
140
  end
148
-
149
141
  end
150
142
 
151
143
  describe ':within_circle :within_spherical_circle' do
@@ -169,41 +161,49 @@ describe Mongoid::Geospatial::Point do
169
161
  Person.new(location: [-73.98, 40.75])
170
162
  end
171
163
 
172
- it 'returns the documents within a center_circle' do
164
+ it 'returns the documents within a circle' do
165
+ pending 'Moped'
173
166
  expect(Bar.where(:location.within_circle =>
174
167
  [elvis.location, 250.0 /
175
168
  Mongoid::Geospatial::EARTH_RADIUS_KM]).to_a)
176
169
  .to eq([mile1])
177
170
  end
178
171
 
179
- it 'returns the documents within a center_circle' do
172
+ it 'returns the documents within a circle' do
173
+ pending 'Moped'
180
174
  expect(Bar.where(:location.within_circle => [elvis.location,
181
- 500.0 / Mongoid::Geospatial::EARTH_RADIUS_KM])
175
+ 500.0 / Mongoid::Geospatial::EARTH_RADIUS_KM])
182
176
  .to_a).to include(mile3)
183
177
  end
184
178
 
185
- it 'returns the documents within a center_sphere' do
179
+ it 'returns the documents within a spherical circle' do
180
+ pending 'Moped'
186
181
  expect(Bar.where(:location.within_spherical_circle =>
187
182
  [elvis.location, 0.0005]).to_a).to eq([mile1])
188
183
  end
189
184
 
190
- it 'returns the documents within a center_sphere' do
185
+ it 'returns the documents within a spherical circle 2' do
186
+ pending 'Moped'
191
187
  expect(Bar.where(:location.within_spherical_circle =>
192
188
  [elvis.location, 0.5]).to_a).to include(mile9)
193
189
  end
194
190
 
191
+ it 'returns the documents within a center circle' do
192
+ pending 'Moped'
193
+ expect(Bar.where(:location.within_center_circle =>
194
+ [elvis.location, 0.0005]).to_a).to eq([mile1])
195
+ end
196
+
195
197
  it 'returns the documents within a box' do
198
+ pending 'Moped'
196
199
  expect(Bar.within_box(location: [elvis.location,
197
- elvis.location.map(&:ceil)]).to_a)
200
+ elvis.location.map(&:ceil)]).to_a)
198
201
  .to eq([mile3])
199
202
  end
200
-
201
203
  end
202
-
203
204
  end
204
205
 
205
206
  describe '(de)mongoize' do
206
-
207
207
  it 'should mongoize array' do
208
208
  bar = Bar.new(location: [10, -9])
209
209
  expect(bar.location.class).to eql(Mongoid::Geospatial::Point)
@@ -236,19 +236,13 @@ describe Mongoid::Geospatial::Point do
236
236
  # geom.to_geo
237
237
 
238
238
  describe 'with rgeo' do
239
-
240
239
  describe 'instantiated' do
241
-
242
240
  let(:bar) { Bar.create!(name: 'Vitinho', location: [10, 10]) }
243
241
 
244
242
  it 'should demongoize to rgeo' do
245
243
  expect(bar.location.class).to eql(Mongoid::Geospatial::Point)
246
244
  end
247
-
248
245
  end
249
-
250
246
  end
251
-
252
247
  end
253
-
254
248
  end
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongoid::Geospatial::Polygon do
4
-
5
4
  describe '(de)mongoize' do
6
-
7
5
  it 'should support a field mapped as polygon' do
8
6
  farm = Farm.new(area: [[5, 5], [6, 5], [6, 6], [5, 6]])
9
7
  expect(farm.area).to be_a Mongoid::Geospatial::Polygon
@@ -38,13 +36,10 @@ describe Mongoid::Geospatial::Polygon do
38
36
  describe 'with rgeo' do
39
37
  # farm.area.should be_a RGeo::Geographic::SphericalPolygonImpl
40
38
  end
41
-
42
39
  end
43
40
 
44
41
  describe 'query' do
45
-
46
42
  context ':box, :polygon' do
47
-
48
43
  before do
49
44
  Farm.create_indexes
50
45
  end
@@ -58,27 +53,28 @@ describe Mongoid::Geospatial::Polygon do
58
53
  end
59
54
 
60
55
  it 'returns the documents within a box' do
56
+ pending 'Moped'
61
57
  expect(Farm.where(:geom.within_polygon =>
62
58
  ranch.area).to_a).to eq([ranch])
63
59
  end
64
60
 
65
61
  it 'returns the documents within a polygon' do
62
+ pending 'Moped'
66
63
  expect(Farm.where(:geom.within_polygon =>
67
64
  farm.area).to_a).to eq([farm])
68
65
  end
69
66
 
70
67
  it 'returns the documents within a center' do
68
+ pending 'Moped'
71
69
  expect(Farm.where(:geom.within_circle =>
72
70
  [ranch.geom, 0.4]).first).to eq(ranch)
73
71
  end
74
72
 
75
73
  it 'returns the documents within a center_sphere' do
74
+ pending 'Moped'
76
75
  expect(Farm.where(:geom.within_spherical_circle =>
77
76
  [ranch.geom, 0.1]).first).to eq(ranch)
78
77
  end
79
-
80
78
  end
81
-
82
79
  end
83
-
84
80
  end
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongoid::Geospatial do
4
-
5
4
  context 'Class Stuff' do
6
-
7
5
  it 'should have an lng_symbols accessor' do
8
6
  expect(Mongoid::Geospatial.lng_symbols).to be_instance_of Array
9
7
  expect(Mongoid::Geospatial.lng_symbols).to include :x
@@ -13,11 +11,9 @@ describe Mongoid::Geospatial do
13
11
  expect(Mongoid::Geospatial.lat_symbols).to be_instance_of Array
14
12
  expect(Mongoid::Geospatial.lat_symbols).to include :y
15
13
  end
16
-
17
14
  end
18
15
 
19
16
  context 'Creating indexes' do
20
-
21
17
  it 'should create a 2d index' do
22
18
  Bar.create_indexes
23
19
  expect(Bar.collection.indexes[location: '2d']).not_to be_nil
@@ -27,11 +23,9 @@ describe Mongoid::Geospatial do
27
23
  Alarm.create_indexes
28
24
  expect(Alarm.collection.indexes[spot: '2dsphere']).not_to be_nil
29
25
  end
30
-
31
26
  end
32
27
 
33
28
  context '#nearby 2d' do
34
-
35
29
  before do
36
30
  Bar.create_indexes
37
31
  end
@@ -44,14 +38,12 @@ describe Mongoid::Geospatial do
44
38
  Bar.create(name: 'lax', location: [-118.40, 33.94])
45
39
  end
46
40
 
47
- it 'should work with specifying specific center and different location attribute on collction' do
41
+ it 'should work specifing center and different location' do
48
42
  expect(Bar.nearby(lax.location)).to eq([lax, jfk])
49
43
  end
50
-
51
44
  end
52
45
 
53
46
  context '#nearby 2dsphere' do
54
-
55
47
  before do
56
48
  Alarm.create_indexes
57
49
  end
@@ -139,5 +131,4 @@ describe Mongoid::Geospatial do
139
131
  # Bar.geo_near([1,1], :page => 1, :per_page => 5).size.should == 5
140
132
  # end
141
133
  end
142
-
143
134
  end
@@ -1,15 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongoid::Fields do
4
-
5
4
  context 'delegate' do
6
-
7
5
  before do
8
6
  Bus.create_indexes
9
7
  end
10
8
 
11
9
  context 'x, y helpers' do
12
-
13
10
  let(:bus) { Bus.create!(name: 'Far', location: [7, 8]) }
14
11
 
15
12
  it 'should set instance method x' do
@@ -29,18 +26,19 @@ describe Mongoid::Fields do
29
26
  bus.y = 9
30
27
  expect(bus.y).to eq(9)
31
28
  end
32
-
33
29
  end
34
30
 
35
31
  it 'should set instance methods x= and y=' do
36
32
  bus = Bus.create!(name: 'B', location: [7, 7])
37
- bus.x = 9; bus.y = 9
33
+ bus.x = 9
34
+ bus.y = 9
38
35
  expect(bus.location.to_a).to eq([9, 9])
39
36
  end
40
37
 
41
38
  it 'should work fine with default values' do
42
39
  event = Event.create!(name: 'Bvent')
43
- event.x = 9; event.y = 9
40
+ event.x = 9
41
+ event.y = 9
44
42
  expect(event.location.to_a).to eq([9, 9])
45
43
  end
46
44
 
@@ -48,7 +46,5 @@ describe Mongoid::Fields do
48
46
  bus = Bus.create!(name: 'B', location: nil)
49
47
  expect { bus.x = 9; bus.y = 9 }.to raise_error(NoMethodError)
50
48
  end
51
-
52
49
  end
53
-
54
50
  end
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongoid::Fields do
4
-
5
4
  context 'spatial' do
6
-
7
5
  before do
8
6
  Bar.create_indexes
9
7
  end
@@ -27,10 +25,8 @@ describe Mongoid::Fields do
27
25
  # near = Bar.create!(name: "Near", location: [2,2])
28
26
  # Bar.near_location([1,1]).should eq([near, far])
29
27
  # end
30
-
31
28
  end
32
29
 
33
30
  context 'geom' do
34
31
  end
35
-
36
32
  end
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongoid::Fields do
4
-
5
4
  context 'spatial' do
6
-
7
5
  before do
8
6
  Alarm.create_indexes
9
7
  end
@@ -20,7 +18,5 @@ describe Mongoid::Fields do
20
18
  far = Alarm.create!(name: 'Far', spot: [7, 7])
21
19
  expect(far.spot).to be_instance_of(Mongoid::Geospatial::Point)
22
20
  end
23
-
24
21
  end
25
-
26
22
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongoid::Geospatial::Point do
4
-
5
4
  it 'should not interfer with mongoid' do
6
5
  Place.create!(name: "Moe's")
7
6
  expect(Place.count).to eql(1)
@@ -13,14 +12,12 @@ describe Mongoid::Geospatial::Point do
13
12
  end
14
13
 
15
14
  describe 'queryable' do
16
-
17
15
  before do
18
16
  Mongoid::Geospatial.with_georuby!
19
17
  Place.create_indexes
20
18
  end
21
19
 
22
20
  describe '(de)mongoize' do
23
-
24
21
  it 'should mongoize array' do
25
22
  geom = Place.new(location: [10, -9]).location
26
23
  expect(geom.class).to eql(Mongoid::Geospatial::Point)
@@ -49,17 +46,17 @@ describe Mongoid::Geospatial::Point do
49
46
  end
50
47
 
51
48
  describe 'simple features' do
52
-
53
49
  it 'should mongoize lines' do
54
50
  river = River.new(course: [[1, 2], [3, 4], [5, 6]])
55
- expect(river.course.to_geo).to be_instance_of(GeoRuby::SimpleFeatures::LineString)
51
+ expect(river.course.to_geo)
52
+ .to be_instance_of(GeoRuby::SimpleFeatures::LineString)
56
53
  end
57
54
 
58
55
  it 'should mongoize polygon' do
59
56
  farm = Farm.new(area: [[1, 2], [3, 4], [5, 6]])
60
- expect(farm.area.to_geo).to be_instance_of(GeoRuby::SimpleFeatures::Polygon)
57
+ expect(farm.area.to_geo)
58
+ .to be_instance_of(GeoRuby::SimpleFeatures::Polygon)
61
59
  end
62
-
63
60
  end
64
61
  end
65
62
  end
@@ -1,26 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'RGeo Wrapper' do
4
-
5
- before(:all) do
6
- # Mongoid::Geospatial.send(:remove_const, 'Point')
7
- # Mongoid::Geospatial.send(:remove_const, 'Polygon')
8
- # Mongoid::Geospatial.send(:remove_const, 'Line')
9
-
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
-
14
- # Object.send(:remove_const, 'Bar')
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"
22
- end
23
-
24
4
  describe Mongoid::Geospatial::Point do
25
5
  it 'should not interfer with mongoid' do
26
6
  Bar.create!(name: "Moe's")
@@ -39,9 +19,9 @@ describe 'RGeo Wrapper' do
39
19
  expect(Farm.count).to eql(1)
40
20
  end
41
21
 
42
- it 'should not respond to to_geo before loading external' do
22
+ it 'should respond to to_geo' do
43
23
  farm = Farm.create!(area: [[5, 5], [6, 5], [6, 6], [5, 6]])
44
- expect(farm.area).not_to respond_to(:to_geo)
24
+ expect(farm.area).to respond_to(:to_geo)
45
25
  end
46
26
  end
47
27
 
@@ -51,14 +31,13 @@ describe 'RGeo Wrapper' do
51
31
  expect(River.count).to eql(1)
52
32
  end
53
33
 
54
- it 'should not respond to to_geo before loading external' do
34
+ it 'should respond to to_geo before loading external' do
55
35
  river = River.create!(course: [[5, 5], [6, 5], [6, 6], [5, 6]])
56
- expect(river.course).not_to respond_to(:to_geo)
36
+ expect(river.course).to respond_to(:to_geo)
57
37
  end
58
38
  end
59
39
 
60
40
  describe 'queryable' do
61
-
62
41
  before do
63
42
  Mongoid::Geospatial.with_rgeo!
64
43
  Bar.create_indexes
@@ -67,20 +46,32 @@ describe 'RGeo Wrapper' do
67
46
  end
68
47
 
69
48
  describe '(de)mongoize' do
70
-
71
49
  describe Mongoid::Geospatial::Point do
72
50
  it 'should mongoize array' do
73
51
  geom = Bar.new(location: [10, -9]).location
74
52
  expect(geom.class).to eql(Mongoid::Geospatial::Point)
75
- expect(geom.to_rgeo.class).to eql(RGeo::Geographic::SphericalPointImpl)
76
53
  expect(geom.x).to be_within(0.1).of(10)
54
+ end
55
+
56
+ it 'should wrap to georuby' do
57
+ geom = Bar.new(location: [10, -9]).location
58
+ expect(geom.to_geo.class)
59
+ .to eql(GeoRuby::SimpleFeatures::Point)
60
+ expect(geom.to_geo.y).to be_within(0.1).of(-9)
61
+ end
62
+
63
+ it 'should wrap to rgeo' do
64
+ geom = Bar.new(location: [10, -9]).location
65
+ expect(geom.to_rgeo.class)
66
+ .to eql(RGeo::Geographic::SphericalPointImpl)
77
67
  expect(geom.to_rgeo.y).to be_within(0.1).of(-9)
78
68
  end
79
69
 
80
70
  it 'should mongoize hash' do
81
71
  geom = Bar.new(location: { x: 10, y: -9 }).location
82
72
  expect(geom.class).to eql(Mongoid::Geospatial::Point)
83
- expect(geom.to_rgeo.class).to eql(RGeo::Geographic::SphericalPointImpl)
73
+ expect(geom.to_rgeo.class)
74
+ .to eql(RGeo::Geographic::SphericalPointImpl)
84
75
  end
85
76
 
86
77
  it 'should accept an RGeo object' do
@@ -92,8 +83,9 @@ describe 'RGeo Wrapper' do
92
83
 
93
84
  it 'should calculate 3d distances by default' do
94
85
  bar = Bar.create! location: [-73.77694444, 40.63861111]
95
- bar2 = Bar.create! location: [-118.40, 33.94] # ,:unit=>:mi, :spherical => true)
96
- expect(bar.location.rgeo_distance(bar2.location).to_i).to be_within(1).of(3_978_262)
86
+ bar2 = Bar.create! location: [-118.40, 33.94] # ,:unit=>:mi
87
+ expect(bar.location.rgeo_distance(bar2.location).to_i)
88
+ .to be_within(1).of(3_978_262)
97
89
  end
98
90
  end
99
91
 
@@ -22,21 +22,8 @@ require 'mongoid'
22
22
  require 'rspec'
23
23
  require 'mongoid/geospatial'
24
24
 
25
- # These environment variables can be set if wanting to test against a database
26
- # that is not on the local machine.
27
- ENV['MONGOID_SPEC_HOST'] ||= 'localhost'
28
- ENV['MONGOID_SPEC_PORT'] ||= '27018'
29
-
30
- # These are used when creating any connection in the test suite.
31
- HOST = ENV['MONGOID_SPEC_HOST']
32
- PORT = ENV['MONGOID_SPEC_PORT'].to_i
33
-
34
25
  LOGGER = Logger.new($stdout)
35
26
 
36
- if RUBY_VERSION >= '1.9.2'
37
- YAML::ENGINE.yamler = 'syck'
38
- end
39
-
40
27
  puts "Running with Mongoid v#{Mongoid::VERSION}"
41
28
 
42
29
  Mongoid.configure do |config|
@@ -51,10 +38,6 @@ end
51
38
 
52
39
  Dir[File.join(SUPPORT, '*.rb')].each { |file| require File.basename(file) }
53
40
 
54
- def bson_object_id_class
55
- Moped::BSON::ObjectId
56
- end
57
-
58
41
  RSpec.configure do |config|
59
42
  # config.mock_with(:mocha)
60
43
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-geospatial
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Ong
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-22 00:00:00.000000000 Z
12
+ date: 2015-01-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
@@ -69,6 +69,7 @@ files:
69
69
  - MIT-LICENSE
70
70
  - README.md
71
71
  - Rakefile
72
+ - bench/bench
72
73
  - lib/mongoid/geospatial.rb
73
74
  - lib/mongoid/geospatial/ext/rgeo_spherical_point_impl.rb
74
75
  - lib/mongoid/geospatial/fields/box.rb
@@ -130,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
131
  version: '0'
131
132
  requirements: []
132
133
  rubyforge_project:
133
- rubygems_version: 2.4.3
134
+ rubygems_version: 2.4.5
134
135
  signing_key:
135
136
  specification_version: 4
136
137
  summary: Mongoid Extension that simplifies MongoDB Geospatial Operations.