mongoid_geospatial 1.0.0rc1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. data/README.md +5 -0
  2. data/lib/mongoid_geospatial.rb +0 -2
  3. data/lib/mongoid_geospatial/contexts/mongo.rb +6 -8
  4. data/lib/mongoid_geospatial/criteria.rb +6 -1
  5. data/lib/mongoid_geospatial/criterion/near_spatial.rb +7 -5
  6. data/lib/mongoid_geospatial/criterion/within_spatial.rb +7 -5
  7. data/lib/mongoid_geospatial/extensions/symbol.rb +31 -31
  8. data/lib/mongoid_geospatial/fields/line_string.rb +2 -4
  9. data/lib/mongoid_geospatial/fields/point.rb +4 -6
  10. data/lib/mongoid_geospatial/fields/polygon.rb +2 -4
  11. data/lib/mongoid_geospatial/geospatial.rb +26 -22
  12. data/lib/mongoid_geospatial/geospatial/core_ext.rb +7 -5
  13. data/lib/mongoid_geospatial/version.rb +1 -1
  14. data/mongoid_geospatial.gemspec +1 -1
  15. data/spec/functional/criterion/inclusion_spec.rb +7 -3
  16. data/spec/functional/{spatial → geospatial}/geo_near_results_spec.rb +0 -0
  17. data/spec/{unit → mongoid_geospatial}/criterion/complex_spec.rb +0 -0
  18. data/spec/{unit → mongoid_geospatial}/criterion/inclusion_spec.rb +0 -0
  19. data/spec/{unit → mongoid_geospatial}/criterion/near_spatial_spec.rb +0 -0
  20. data/spec/mongoid_geospatial/criterion/within_spatial_spec.rb +54 -0
  21. data/spec/mongoid_geospatial/geospatial_spec.rb +25 -0
  22. data/spec/spec_helper.rb +5 -2
  23. data/spec/{config → support}/mongod.conf +0 -0
  24. data/spec/support/mongoid.yml +19 -0
  25. metadata +86 -41
  26. data/lib/mongoid_geospatial/criterion.rb +0 -3
  27. data/lib/mongoid_geospatial/extensions/hash.rb +0 -22
  28. data/spec/config/mongoid.yml +0 -18
  29. data/spec/unit/criterion/within_spatial_spec.rb +0 -52
data/README.md CHANGED
@@ -4,6 +4,11 @@ Mongoid Geospatial
4
4
  A Mongoid Extension that simplifies and adds support for MongoDB and
5
5
  RGeo Spatial Calculations.
6
6
 
7
+ *WARNING* There are no plans to support MongoDB < 2.0.
8
+
9
+ *WARNING* Experimental Mongoid 3.0 support.
10
+
11
+
7
12
  Quick Start
8
13
  -----------
9
14
  Add mongoid_geospatial to your Gemfile:
@@ -4,8 +4,6 @@ require 'active_support/core_ext/string/inflections'
4
4
  require 'active_support/concern'
5
5
  require 'mongoid_geospatial/contexts/mongo'
6
6
  require 'mongoid_geospatial/criteria'
7
- require 'mongoid_geospatial/criterion'
8
- require 'mongoid_geospatial/extensions/hash'
9
7
  require 'mongoid_geospatial/extensions/symbol'
10
8
  require 'mongoid_geospatial/field_option'
11
9
  require 'mongoid_geospatial/fields/point'
@@ -19,7 +19,7 @@ module Mongoid #:nodoc:
19
19
  #
20
20
  # Address.geo_near([70,40], :max_distance => 5, :unit => 5)
21
21
  #
22
- # @param [ Array, Hash, #to_lng_lat ] center The center of where to calculate distance from
22
+ # @param [ Array, Hash, #to_xy ] center The center of where to calculate distance from
23
23
  # @param [ Hash ] opts the options to query with
24
24
  # @options opts [Integer] :num The number of rows to fetch
25
25
  # @options opts [Hash] :query The query to filter the rows by, accepts
@@ -33,7 +33,7 @@ module Mongoid #:nodoc:
33
33
  def geo_near(center, opts = {})
34
34
  opts = self.options.merge(opts)
35
35
  # convert point
36
- center = center.to_lng_lat if center.respond_to?(:to_lng_lat)
36
+ center = center.to_xy if center.respond_to?(:to_xy)
37
37
  center = [center.x, center.y] if center.respond_to?(:x)
38
38
 
39
39
  # set default opts
@@ -101,13 +101,11 @@ module Mongoid #:nodoc:
101
101
  query['maxDistance'] = query['maxDistance']/opts[:unit].to_f if opts[:unit]
102
102
  end
103
103
 
104
- if klass.db.connection.server_version >= '1.7'
105
- query['spherical'] = true if opts[:spherical]
104
+ query['spherical'] = true if opts[:spherical]
106
105
 
107
- # mongodb < 1.7 returns degrees but with earth flat. in Mongodb 1.7 you can set sphere and let mongodb calculate the distance in Miles or KM
108
- # for mongodb < 1.7 we need to run Haversine first before calculating degrees to Km or Miles. See below.
109
- query['distanceMultiplier'] = opts[:distance_multiplier].to_f if opts[:distance_multiplier]
110
- end
106
+ # mongodb < 1.7 returns degrees but with earth flat. in Mongodb 1.7 you can set sphere and let mongodb calculate the distance in Miles or KM
107
+ # for mongodb < 1.7 we need to run Haversine first before calculating degrees to Km or Miles. See below.
108
+ query['distanceMultiplier'] = opts[:distance_multiplier].to_f if opts[:distance_multiplier]
111
109
  query
112
110
  end
113
111
  end
@@ -1,5 +1,10 @@
1
+ require 'mongoid_geospatial/criterion/complex'
2
+ require 'mongoid_geospatial/criterion/near_spatial'
3
+ require 'mongoid_geospatial/criterion/within_spatial'
4
+
5
+
1
6
  module Mongoid #:nodoc:
2
7
  class Criteria
3
- delegate :geo_near, :to => :context
8
+ delegate :geo_near, :to => :context
4
9
  end
5
10
  end
@@ -6,9 +6,9 @@ module Mongoid #:nodoc:
6
6
  # get a shorthand syntax for where clauses.
7
7
  #
8
8
  # @example Coninputersion of a simple to complex criterion.
9
- # { :field => { "$nearSphere" => => [20,30]}, '$maxDistance' => 5 }
9
+ # { :field => { "$nearSphere" => [20,30]}, '$maxDistance' => 5 }
10
10
  # becomes:
11
- # { :field.near(:sphere) => {:point => [20,30], :max => 5, :unit => :km} }
11
+ # { :field.near_sphere => {:point => [20,30], :max => 5, :unit => :km} }
12
12
  class NearSpatial < Complex
13
13
 
14
14
  # Coninputert input to query for near or nearSphere
@@ -19,9 +19,11 @@ module Mongoid #:nodoc:
19
19
  #
20
20
  # @param [Hash,Array] input input to coninputer to query
21
21
  def to_mongo_query(input)
22
- if input.kind_of?(Hash)
22
+ if input.respond_to?(:x)
23
+ {"$#{operator}" => [input.x, input.y]} #, '$maxDistance' => input[1] }
24
+ elsif input.kind_of?(Hash)
23
25
  raise ':point required to make valid query' unless input[:point]
24
- input[:point] = input[:point].to_lng_lat if input[:point].respond_to?(:to_lng_lat)
26
+ input[:point] = input[:point].to_xy if input[:point].respond_to?(:to_xy)
25
27
  query = {"$#{operator}" => input[:point] }
26
28
  if input[:max]
27
29
  query['$maxDistance'] = input[:max].to_f
@@ -38,7 +40,7 @@ module Mongoid #:nodoc:
38
40
  if input.first.kind_of? Numeric
39
41
  {"$#{operator}" => input }
40
42
  else
41
- input[0] = input[0].to_lng_lat if input[0].respond_to?(:to_lng_lat)
43
+ input[0] = input[0].to_xy if input[0].respond_to?(:to_xy)
42
44
  {"$#{operator}" => input[0], '$maxDistance' => input[1] }
43
45
  end
44
46
  end
@@ -19,18 +19,20 @@ module Mongoid #:nodoc:
19
19
  #
20
20
  # @param [Hash,Array] input Variable to conver to query
21
21
  def to_mongo_query(input)
22
- if ['box','polygon'].index(@operator)
22
+ if ['box','polygon'].include?(@operator)
23
23
  input = input.values if input.kind_of?(Hash)
24
24
  if input.respond_to?(:map)
25
- input.map!{ |v| (v.respond_to?(:to_lng_lat)) ? v.to_lng_lat : v }
25
+ input.map! do |v|
26
+ v.respond_to?(:to_xy) ? v.to_xy : v
27
+ end
26
28
  else
27
29
  input
28
30
  end
29
- elsif ['center','centerSphere'].index(@operator)
31
+ elsif ['center','centerSphere'].include?(@operator)
30
32
 
31
33
  if input.kind_of?(Hash) || input.kind_of?(ActiveSupport::OrderedHash)
32
34
  raise ':point required to make valid query' unless input[:point]
33
- input[:point] = input[:point].to_lng_lat if input[:point].respond_to?(:to_lng_lat)
35
+ input[:point] = input[:point].to_xy if input[:point].respond_to?(:to_xy)
34
36
  if input[:max]
35
37
  input[:max] = input[:max].to_f
36
38
 
@@ -48,7 +50,7 @@ module Mongoid #:nodoc:
48
50
  end
49
51
 
50
52
  if input.kind_of? Array
51
- input[0] = input[0].to_lng_lat if input[0].respond_to?(:to_lng_lat)
53
+ input[0] = input[0].to_xy if input[0].respond_to?(:to_xy)
52
54
  end
53
55
 
54
56
  end
@@ -2,45 +2,45 @@
2
2
  module Mongoid #:nodoc:
3
3
  module Extensions #:nodoc:
4
4
  module Symbol #:nodoc:
5
- module Inflections #:nodoc:
6
5
 
7
- # return a class that will accept a value to convert the query correctly for near
8
- #
9
- # @param [Symbol] calc This accepts :sphere
10
- #
11
- # @return [Criterion::NearSpatial]
6
+ # return a class that will accept a value to convert the query correctly for near
7
+ #
8
+ # @param [Symbol] calc This accepts :sphere
9
+ #
10
+ # @return [Criterion::NearSpatial]
12
11
 
13
- def near(calc = :flat)
14
- Criterion::NearSpatial.new(:operator => get_op('near',calc), :key => self)
15
- end
12
+ def near(calc = :flat)
13
+ Criterion::NearSpatial.new(:operator => get_op('near',calc), :key => self)
14
+ end
16
15
 
17
- # alias for self.near(:sphere)
18
- #
19
- # @return [Criterion::NearSpatial]
20
- def near_sphere
21
- self.near(:sphere)
22
- end
16
+ # alias for self.near(:sphere)
17
+ #
18
+ # @return [Criterion::NearSpatial]
19
+ def near_sphere
20
+ self.near(:sphere)
21
+ end
23
22
 
24
- # @param [Symbol] shape :box,:polygon,:center,:center_sphere
25
- #
26
- # @return [Criterion::WithinSpatial]
27
- def within(shape)
28
- shape = get_op(:center,:sphere) if shape == :center_sphere
29
- Criterion::WithinSpatial.new(:operator => shape.to_s , :key => self)
30
- end
23
+ # @param [Symbol] shape :box,:polygon,:center,:center_sphere
24
+ #
25
+ # @return [Criterion::WithinSpatial]
26
+ def within(shape)
27
+ shape = get_op(:center,:sphere) if shape == :center_sphere
28
+ Criterion::WithinSpatial.new(:operator => shape.to_s , :key => self)
29
+ end
31
30
 
32
- private
31
+ private
33
32
 
34
- def get_op operator, calc
35
- if calc.to_sym == :sphere && Mongoid.master.connection.server_version >= '1.7'
36
- "#{operator}Sphere"
37
- elsif calc.to_sym == :sphere
38
- raise "MongoDB Server version #{Mongoid.master.connection.server_version} does not have Spherical Calculation"
39
- else
40
- operator.to_s
41
- end
33
+ def get_op operator, calc
34
+ if calc.to_sym == :sphere
35
+ "#{operator}Sphere"
36
+ else
37
+ operator.to_s
42
38
  end
43
39
  end
40
+
44
41
  end
45
42
  end
46
43
  end
44
+
45
+
46
+ ::Symbol.__send__(:include, Mongoid::Extensions::Symbol)
@@ -2,13 +2,11 @@ module Mongoid
2
2
  module Geospatial
3
3
  class LineString
4
4
 
5
- include Mongoid::Fields::Serializable
6
-
7
- def deserialize(object)
5
+ def mongoize(object)
8
6
  RGeo::Geographic.spherical_factory.line_string *object
9
7
  end
10
8
 
11
- def serialize(object)
9
+ def demongoize(object)
12
10
  object.to_a
13
11
  end
14
12
 
@@ -2,15 +2,13 @@ module Mongoid
2
2
  module Geospatial
3
3
  class Point
4
4
 
5
- include Mongoid::Fields::Serializable
6
-
7
- def deserialize(object)
5
+ def mongoize(object)
8
6
  return unless object && !object.empty?
9
7
  RGeo::Geographic.spherical_factory.point *object
10
8
  #["x"], object["y"]
11
9
  end
12
10
 
13
- def serialize(object)
11
+ def demongoize(object)
14
12
  object.respond_to?(:x) ? [object.x, object.y] : object
15
13
  # if object.respond_to? :x
16
14
  # { "x" => object.x, "y" => object.y }
@@ -36,8 +34,8 @@ module Mongoid
36
34
  # - define_method "#{field.name}=" do |arg|
37
35
  # - if arg.kind_of?(Hash) && arg[lng_meth] && arg[lat_meth]
38
36
  # - arg = [arg[lng_meth].to_f, arg[lat_meth].to_f]
39
- # - elsif arg.respond_to?(:to_lng_lat)
40
- # - arg = arg.to_lng_lat
37
+ # - elsif arg.respond_to?(:to_xy)
38
+ # - arg = arg.to_xy
41
39
  # - end
42
40
  # - self[field.name]=arg
43
41
  # - arg = [nil,nil] if arg.nil?
@@ -2,9 +2,7 @@ module Mongoid
2
2
  module Geospatial
3
3
  class Polygon
4
4
 
5
- include Mongoid::Fields::Serializable
6
-
7
- def deserialize(object)
5
+ def mongoize(object)
8
6
  points = object.map do |pair|
9
7
  RGeo::Geographic.spherical_factory.point *pair
10
8
  end
@@ -12,7 +10,7 @@ module Mongoid
12
10
  RGeo::Geographic.spherical_factory.polygon ring
13
11
  end
14
12
 
15
- def serialize(object)
13
+ def demongoize(object)
16
14
  object #.flatten
17
15
  end
18
16
 
@@ -19,6 +19,26 @@ module Mongoid
19
19
  }
20
20
 
21
21
  GEO_FACTORY = RGeo::Geographic.spherical_factory
22
+ RAD_PER_DEG = Math::PI/180
23
+ mattr_accessor :lng_symbols
24
+ @@lng_symbols = LNG_SYMBOLS.dup
25
+
26
+ mattr_accessor :lat_symbols
27
+ @@lat_symbols = LAT_SYMBOLS.dup
28
+
29
+ mattr_accessor :earth_radius
30
+ @@earth_radius = EARTH_RADIUS.dup
31
+
32
+ mattr_accessor :paginator
33
+ @@paginator = :array
34
+
35
+ mattr_accessor :default_per_page
36
+ @@default_per_page = 25
37
+
38
+ # mattr_accessor :spherical_distance_formula
39
+ # @@spherical_distance_formula = :n_vector
40
+ mattr_accessor :geo_factory
41
+ @@geo_factory = GEO_FACTORY.dup
22
42
 
23
43
  included do
24
44
  attr_accessor :geo
@@ -32,9 +52,13 @@ module Mongoid
32
52
  # @param [String,Symbol] name
33
53
  # @param [Hash] options options for spatial_index
34
54
 
35
- def spatial_index name, *options
55
+ def spatial_index name, options = {}
36
56
  self.spatial_fields_indexed << name
37
- index [[ name, Mongo::GEO2D ]], *options
57
+ if Mongoid::VERSION =~ /3.0/
58
+ index name => '2d', :options => options
59
+ else
60
+ index [[name, '2d']], options
61
+ end
38
62
  end
39
63
  end
40
64
 
@@ -60,26 +84,6 @@ module Mongoid
60
84
  # rads
61
85
 
62
86
  # end
63
- RAD_PER_DEG = Math::PI/180
64
- mattr_accessor :lng_symbols
65
- @@lng_symbols = LNG_SYMBOLS.dup
66
-
67
- mattr_accessor :lat_symbols
68
- @@lat_symbols = LAT_SYMBOLS.dup
69
-
70
- mattr_accessor :earth_radius
71
- @@earth_radius = EARTH_RADIUS.dup
72
-
73
- mattr_accessor :paginator
74
- @@paginator = :array
75
-
76
- mattr_accessor :default_per_page
77
- @@default_per_page = 25
78
-
79
- # mattr_accessor :spherical_distance_formula
80
- # @@spherical_distance_formula = :n_vector
81
- mattr_accessor :geo_factory
82
- @@lng_symbols = GEO_FACTORY.dup
83
87
 
84
88
 
85
89
  end
@@ -1,16 +1,18 @@
1
1
  class Array
2
- def to_lng_lat
2
+ def to_xy
3
3
  self[0..1].map(&:to_f)
4
4
  end
5
+ alias :to_lng_lat :to_xy
5
6
  end
6
7
 
7
8
  class Hash
8
- def to_lng_lat
9
+ def to_xy
9
10
  raise "Hash must have at least 2 items" if self.size < 2
10
- [to_lng, to_lat]
11
+ [to_x, to_y]
11
12
  end
13
+ alias :to_lng_lat :to_xy
12
14
 
13
- def to_lat
15
+ def to_y
14
16
  v = (Mongoid::Geospatial.lat_symbols & self.keys).first
15
17
  return self[v].to_f if !v.nil? && self[v]
16
18
  raise "Hash must contain #{Mongoid::Geospatial.lat_symbols.inspect} if ruby version is less than 1.9" if RUBY_VERSION.to_f < 1.9
@@ -18,7 +20,7 @@ class Hash
18
20
  self.values[1].to_f
19
21
  end
20
22
 
21
- def to_lng
23
+ def to_x
22
24
  v = (Mongoid::Geospatial.lng_symbols & self.keys).first
23
25
  return self[v].to_f if !v.nil? && self[v]
24
26
  raise "Hash cannot contain #{Mongoid::Geospatial.lat_symbols.inspect} as the first item if there is no #{Mongoid::Geospatial.lng_symbols.inspect}" if Mongoid::Geospatial.lat_symbols.index(self.keys[0])
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Geospatial
3
- VERSION = "1.0.0rc1"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
17
17
 
18
18
 
19
19
  gem.add_dependency('rgeo', ['>= 0.3.5'])
20
- gem.add_dependency('mongoid', ['>= 2.1.0'])
20
+ gem.add_dependency('mongoid', ['>= 2.0.0'])
21
21
  gem.add_dependency('activesupport', ["~> 3.0"])
22
22
  gem.add_development_dependency('yard', ["~>0.6.0"])
23
23
  gem.add_development_dependency('rspec', ['~>2.3'])
@@ -249,15 +249,15 @@ describe Mongoid::Criterion::Inclusion do
249
249
  end
250
250
 
251
251
  let!(:berlin) do
252
- Bar.create(:location => [ 52.30, 13.25 ])
252
+ Bar.create(:name => :berlin, :location => [ 52.30, 13.25 ])
253
253
  end
254
254
 
255
255
  let!(:prague) do
256
- Bar.create(:location => [ 50.5, 14.26 ])
256
+ Bar.create(:name => :prague, :location => [ 50.5, 14.26 ])
257
257
  end
258
258
 
259
259
  let!(:paris) do
260
- Bar.create(:location => [ 48.48, 2.20 ])
260
+ Bar.create(:name => :paris, :location => [ 48.48, 2.20 ])
261
261
  end
262
262
 
263
263
  it "returns the documents sorted closest to furthest" do
@@ -272,6 +272,10 @@ describe Mongoid::Criterion::Inclusion do
272
272
  Bar.where(:location.near_sphere => [ 41.23, 2.9 ]).should == [ paris, prague, berlin ]
273
273
  end
274
274
 
275
+ it "should find closest using rgeo point" do
276
+ Bar.where(:location.near => paris.location).should == [ paris, prague, berlin ]
277
+ end
278
+
275
279
  end
276
280
 
277
281
  context "#within" do
@@ -0,0 +1,54 @@
1
+ require "spec_helper"
2
+
3
+ describe Mongoid::Criterion::WithinSpatial do
4
+
5
+ let(:within) do
6
+ {
7
+ :box => Mongoid::Criterion::WithinSpatial.new(:key => :field, :operator => "box"),
8
+ :center => Mongoid::Criterion::WithinSpatial.new(:key => :field, :operator => "center"),
9
+ :polygon => Mongoid::Criterion::WithinSpatial.new(:key => :field, :operator => "polygon"),
10
+ :center_sphere => Mongoid::Criterion::WithinSpatial.new(:key => :field, :operator => "box"),
11
+ }
12
+ end
13
+
14
+ context "#to_mongo_query" do
15
+
16
+ {
17
+ :box =>
18
+ {
19
+ 'Array of Arrays' => [[10,20], [15,25]],
20
+ 'Array of Hashes' => [{ x: 10, y: 20 }, { x: 15, y: 25 }],
21
+ 'Hash of Hashes' => { a: { x: 10, y: 20 }, b: { x: 15, y: 25 }}
22
+ },
23
+ :polygon =>
24
+ {
25
+ 'Array of Arrays' => [[10,20], [15,25]],
26
+ 'Array of Hashes' => [{ x: 10, y: 20 }, { x: 15, y: 25 }],
27
+ 'Hash of Hashes' => { a: { x: 10, y: 20 }, b: { x: 15, y: 25 }}
28
+ },
29
+ :center =>
30
+ {
31
+ 'Point' => [[1,2],5],
32
+ 'Hash Point' => {:point => [-73.98, 40.77], :max => 5},
33
+ 'Hash Point Unit' => {:point => [-73.98, 40.77], :max => 5, :unit => :km}
34
+ },
35
+ :center_sphere =>
36
+ {
37
+ 'Point' => [[1,2],5],
38
+ 'Hash Point' => {:point => [-73.98, 40.77], :max => 5},
39
+ 'Hash Point Unit' => {:point => [-73.98, 40.77], :max => 5, :unit => :km}
40
+ }
41
+ }.each do |shape, points|
42
+
43
+ points.each do |input_name,input|
44
+
45
+ it "should generate a #{shape} query with '#{input_name}'" do
46
+ within[shape].to_mongo_query(input).should be_a_kind_of(Hash)
47
+ end
48
+
49
+ end
50
+ end
51
+
52
+ end # context
53
+ end # describe
54
+
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+
3
+ describe Mongoid::Geospatial do
4
+
5
+ context "Class Stuff" do
6
+
7
+ it "should have an lng_symbols accessor" do
8
+ Mongoid::Geospatial.lng_symbols.should be_instance_of Array
9
+ Mongoid::Geospatial.lng_symbols.should include :x
10
+ end
11
+
12
+ it "should have an lat_symbols accessor" do
13
+ Mongoid::Geospatial.lat_symbols.should be_instance_of Array
14
+ Mongoid::Geospatial.lat_symbols.should include :y
15
+ end
16
+
17
+ end
18
+
19
+
20
+ context "Included" do
21
+ end
22
+
23
+
24
+
25
+ end
data/spec/spec_helper.rb CHANGED
@@ -19,8 +19,11 @@ if RUBY_VERSION >= '1.9.2'
19
19
  end
20
20
 
21
21
  Mongoid.configure do |config|
22
- name = "mongoid_geospatial_test"
23
- config.master = Mongo::Connection.new.db(name)
22
+ opts = YAML.load(File.read(File.dirname(__FILE__) + '/support/mongoid.yml'))["test"]
23
+ name = opts.delete("database")
24
+ host = opts.delete("host")
25
+ port = opts.delete("port")
26
+ config.master = Mongo::Connection.new(host, port, opts).db(name)
24
27
  config.logger = nil
25
28
  config.allow_dynamic_fields = true
26
29
  end
File without changes
@@ -0,0 +1,19 @@
1
+ test:
2
+ database: mongoid_geospatial_test
3
+ host: localhost
4
+ port: 27018
5
+ slaves:
6
+ # - host: localhost
7
+ # port: 27018
8
+ # - host: localhost
9
+ # port: 27019
10
+ # allow_dynamic_fields: false
11
+ # include_root_in_json: true
12
+ # parameterize_keys: false
13
+ # persist_in_safe_mode: false
14
+ # raise_not_found_error: false
15
+ # reconnect_time: 5
16
+ # autocreate_indexes: false
17
+ # persist_types: false
18
+ # option_no_exist: false
19
+ # skip_version_check: false
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_geospatial
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0rc1
5
- prerelease: 5
4
+ version: 1.0.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ryan Ong
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-31 00:00:00.000000000 Z
13
+ date: 2012-05-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rgeo
17
- requirement: &17414120 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,21 +22,31 @@ dependencies:
22
22
  version: 0.3.5
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *17414120
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 0.3.5
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: mongoid
28
- requirement: &17412660 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ! '>='
32
37
  - !ruby/object:Gem::Version
33
- version: 2.1.0
38
+ version: 2.0.0
34
39
  type: :runtime
35
40
  prerelease: false
36
- version_requirements: *17412660
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 2.0.0
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: activesupport
39
- requirement: &20713780 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ~>
@@ -44,10 +54,15 @@ dependencies:
44
54
  version: '3.0'
45
55
  type: :runtime
46
56
  prerelease: false
47
- version_requirements: *20713780
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '3.0'
48
63
  - !ruby/object:Gem::Dependency
49
64
  name: yard
50
- requirement: &20713300 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
51
66
  none: false
52
67
  requirements:
53
68
  - - ~>
@@ -55,10 +70,15 @@ dependencies:
55
70
  version: 0.6.0
56
71
  type: :development
57
72
  prerelease: false
58
- version_requirements: *20713300
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 0.6.0
59
79
  - !ruby/object:Gem::Dependency
60
80
  name: rspec
61
- requirement: &20712820 !ruby/object:Gem::Requirement
81
+ requirement: !ruby/object:Gem::Requirement
62
82
  none: false
63
83
  requirements:
64
84
  - - ~>
@@ -66,10 +86,15 @@ dependencies:
66
86
  version: '2.3'
67
87
  type: :development
68
88
  prerelease: false
69
- version_requirements: *20712820
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: '2.3'
70
95
  - !ruby/object:Gem::Dependency
71
96
  name: rcov
72
- requirement: &20712340 !ruby/object:Gem::Requirement
97
+ requirement: !ruby/object:Gem::Requirement
73
98
  none: false
74
99
  requirements:
75
100
  - - ! '>='
@@ -77,10 +102,15 @@ dependencies:
77
102
  version: '0'
78
103
  type: :development
79
104
  prerelease: false
80
- version_requirements: *20712340
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
81
111
  - !ruby/object:Gem::Dependency
82
112
  name: mocha
83
- requirement: &20711860 !ruby/object:Gem::Requirement
113
+ requirement: !ruby/object:Gem::Requirement
84
114
  none: false
85
115
  requirements:
86
116
  - - ! '>='
@@ -88,10 +118,15 @@ dependencies:
88
118
  version: '0'
89
119
  type: :development
90
120
  prerelease: false
91
- version_requirements: *20711860
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
92
127
  - !ruby/object:Gem::Dependency
93
128
  name: will_paginate
94
- requirement: &20711380 !ruby/object:Gem::Requirement
129
+ requirement: !ruby/object:Gem::Requirement
95
130
  none: false
96
131
  requirements:
97
132
  - - ! '>='
@@ -99,10 +134,15 @@ dependencies:
99
134
  version: '0'
100
135
  type: :development
101
136
  prerelease: false
102
- version_requirements: *20711380
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
103
143
  - !ruby/object:Gem::Dependency
104
144
  name: kaminari
105
- requirement: &20710900 !ruby/object:Gem::Requirement
145
+ requirement: !ruby/object:Gem::Requirement
106
146
  none: false
107
147
  requirements:
108
148
  - - ! '>='
@@ -110,7 +150,12 @@ dependencies:
110
150
  version: '0'
111
151
  type: :development
112
152
  prerelease: false
113
- version_requirements: *20710900
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
114
159
  description: mongoid_geospatial simplifies spatial calculations. Adds integration
115
160
  into mongoid so pagination and other function continue to work. It adds symbol extensions
116
161
  to simplify query creation.
@@ -129,12 +174,10 @@ files:
129
174
  - lib/mongoid_geospatial.rb
130
175
  - lib/mongoid_geospatial/contexts/mongo.rb
131
176
  - lib/mongoid_geospatial/criteria.rb
132
- - lib/mongoid_geospatial/criterion.rb
133
177
  - lib/mongoid_geospatial/criterion/complex.rb
134
178
  - lib/mongoid_geospatial/criterion/inclusion.rb
135
179
  - lib/mongoid_geospatial/criterion/near_spatial.rb
136
180
  - lib/mongoid_geospatial/criterion/within_spatial.rb
137
- - lib/mongoid_geospatial/extensions/hash.rb
138
181
  - lib/mongoid_geospatial/extensions/symbol.rb
139
182
  - lib/mongoid_geospatial/field_option.rb
140
183
  - lib/mongoid_geospatial/fields/line_string.rb
@@ -146,12 +189,10 @@ files:
146
189
  - lib/mongoid_geospatial/geospatial/geo_near_results.rb
147
190
  - lib/mongoid_geospatial/version.rb
148
191
  - mongoid_geospatial.gemspec
149
- - spec/config/mongod.conf
150
- - spec/config/mongoid.yml
151
192
  - spec/functional/contexts/mongo_spec.rb
152
193
  - spec/functional/criterion/inclusion_spec.rb
194
+ - spec/functional/geospatial/geo_near_results_spec.rb
153
195
  - spec/functional/mongoid_geospatial_spec.rb
154
- - spec/functional/spatial/geo_near_results_spec.rb
155
196
  - spec/models/account.rb
156
197
  - spec/models/acolyte.rb
157
198
  - spec/models/address.rb
@@ -222,12 +263,15 @@ files:
222
263
  - spec/models/vet_visit.rb
223
264
  - spec/models/video.rb
224
265
  - spec/models/wiki_page.rb
266
+ - spec/mongoid_geospatial/criterion/complex_spec.rb
267
+ - spec/mongoid_geospatial/criterion/inclusion_spec.rb
268
+ - spec/mongoid_geospatial/criterion/near_spatial_spec.rb
269
+ - spec/mongoid_geospatial/criterion/within_spatial_spec.rb
270
+ - spec/mongoid_geospatial/geospatial_spec.rb
225
271
  - spec/spec_helper.rb
226
272
  - spec/support/authentication.rb
227
- - spec/unit/criterion/complex_spec.rb
228
- - spec/unit/criterion/inclusion_spec.rb
229
- - spec/unit/criterion/near_spatial_spec.rb
230
- - spec/unit/criterion/within_spatial_spec.rb
273
+ - spec/support/mongod.conf
274
+ - spec/support/mongoid.yml
231
275
  homepage: https://github.com/nofxx/mongoid_geospatial
232
276
  licenses: []
233
277
  post_install_message:
@@ -243,23 +287,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
243
287
  required_rubygems_version: !ruby/object:Gem::Requirement
244
288
  none: false
245
289
  requirements:
246
- - - ! '>'
290
+ - - ! '>='
247
291
  - !ruby/object:Gem::Version
248
- version: 1.3.1
292
+ version: '0'
249
293
  requirements: []
250
294
  rubyforge_project:
251
- rubygems_version: 1.8.11
295
+ rubygems_version: 1.8.23
252
296
  signing_key:
253
297
  specification_version: 3
254
298
  summary: A Mongoid Extension that simplifies and adds support for MongoDB Geo Spatial
255
299
  Calculations.
256
300
  test_files:
257
- - spec/config/mongod.conf
258
- - spec/config/mongoid.yml
259
301
  - spec/functional/contexts/mongo_spec.rb
260
302
  - spec/functional/criterion/inclusion_spec.rb
303
+ - spec/functional/geospatial/geo_near_results_spec.rb
261
304
  - spec/functional/mongoid_geospatial_spec.rb
262
- - spec/functional/spatial/geo_near_results_spec.rb
263
305
  - spec/models/account.rb
264
306
  - spec/models/acolyte.rb
265
307
  - spec/models/address.rb
@@ -330,10 +372,13 @@ test_files:
330
372
  - spec/models/vet_visit.rb
331
373
  - spec/models/video.rb
332
374
  - spec/models/wiki_page.rb
375
+ - spec/mongoid_geospatial/criterion/complex_spec.rb
376
+ - spec/mongoid_geospatial/criterion/inclusion_spec.rb
377
+ - spec/mongoid_geospatial/criterion/near_spatial_spec.rb
378
+ - spec/mongoid_geospatial/criterion/within_spatial_spec.rb
379
+ - spec/mongoid_geospatial/geospatial_spec.rb
333
380
  - spec/spec_helper.rb
334
381
  - spec/support/authentication.rb
335
- - spec/unit/criterion/complex_spec.rb
336
- - spec/unit/criterion/inclusion_spec.rb
337
- - spec/unit/criterion/near_spatial_spec.rb
338
- - spec/unit/criterion/within_spatial_spec.rb
382
+ - spec/support/mongod.conf
383
+ - spec/support/mongoid.yml
339
384
  has_rdoc:
@@ -1,3 +0,0 @@
1
- require 'mongoid_geospatial/criterion/complex'
2
- require 'mongoid_geospatial/criterion/near_spatial'
3
- require 'mongoid_geospatial/criterion/within_spatial'
@@ -1,22 +0,0 @@
1
- # encoding: utf-8
2
- module Mongoid #:nodoc:
3
- module Extensions #:nodoc:
4
- module Hash #:nodoc:
5
- module CriteriaHelpers #:nodoc:
6
- def expand_complex_criteria
7
- hsh = {}
8
- each_pair do |k,v|
9
- if k.respond_to?(:key) && k.respond_to?(:to_mongo_query)
10
- hsh[k.key] ||= {}
11
- hsh[k.key].merge!(k.to_mongo_query(v))
12
- else
13
- hsh[k] = v
14
- end
15
- end
16
- hsh
17
- end
18
- end
19
- end
20
- end
21
- end
22
-
@@ -1,18 +0,0 @@
1
- test:
2
- database: mongoid_config_test
3
- host: localhost
4
- slaves:
5
- # - host: localhost
6
- # port: 27018
7
- # - host: localhost
8
- # port: 27019
9
- allow_dynamic_fields: false
10
- include_root_in_json: true
11
- parameterize_keys: false
12
- persist_in_safe_mode: false
13
- raise_not_found_error: false
14
- reconnect_time: 5
15
- autocreate_indexes: false
16
- persist_types: false
17
- option_no_exist: false
18
- skip_version_check: false
@@ -1,52 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Mongoid::Criterion::WithinSpatial do
4
-
5
- let(:within) do
6
- {
7
- :box => Mongoid::Criterion::WithinSpatial.new(:key => :field, :operator => "box"),
8
- :polygon => Mongoid::Criterion::WithinSpatial.new(:key => :field, :operator => "polygon"),
9
- :center => Mongoid::Criterion::WithinSpatial.new(:key => :field, :operator => "center"),
10
- :center_sphere => Mongoid::Criterion::WithinSpatial.new(:key => :field, :operator => "box"),
11
- }
12
- end
13
- WITHIN = {
14
- :box =>
15
- {
16
- 'Array of Arrays' => [[10,20], [15,25]],
17
- 'Array of Hashes' => [{ x: 10, y: 20 }, { x: 15, y: 25 }],
18
- 'Hash of Hashes' => { a: { x: 10, y: 20 }, b: { x: 15, y: 25 }}
19
- },
20
- :polygon =>
21
- {
22
- 'Array of Arrays' => [[10,20], [15,25]],
23
- 'Array of Hashes' => [{ x: 10, y: 20 }, { x: 15, y: 25 }],
24
- 'Hash of Hashes' => { a: { x: 10, y: 20 }, b: { x: 15, y: 25 }}
25
- },
26
- :center =>
27
- {
28
- 'Point' => [[1,2],5],
29
- 'Hash Point' => {:point => [-73.98, 40.77], :max => 5},
30
- 'Hash Point Unit' => {:point => [-73.98, 40.77], :max => 5, :unit => :km}
31
- },
32
- :center_sphere =>
33
- {
34
- 'Point' => [[1,2],5],
35
- 'Hash Point' => {:point => [-73.98, 40.77], :max => 5},
36
- 'Hash Point Unit' => {:point => [-73.98, 40.77], :max => 5, :unit => :km}
37
- }
38
- }
39
-
40
- context "#to_mongo_query" do
41
-
42
- WITHIN.each do |shape, points|
43
- points.each do |input_name,input|
44
- it "#{shape} should generate a query with #{input_name}" do
45
- within[shape].to_mongo_query(input).should be_a_kind_of(Hash)
46
- end
47
- end
48
- end
49
- end
50
-
51
- end
52
-