Module: Mongoid::Geospatial::ClassMethods
- Defined in:
- lib/mongoid/geospatial.rb
Overview
:nodoc:
Instance Method Summary collapse
- #geo_field(name, options = {}) ⇒ Object
-
#spatial_index(name, options = {}) ⇒ Object
create spatial index for given field www.mongodb.org/display/DOCS/Geospatial+Indexing#GeospatialIndexing-geoNearCommand.
- #spatial_scope(field, _opts = {}) ⇒ Object
- #sphere_index(name, options = {}) ⇒ Object
Instance Method Details
#geo_field(name, options = {}) ⇒ Object
63 64 65 66 |
# File 'lib/mongoid/geospatial.rb', line 63 def geo_field(name, = {}) field name, { type: Mongoid::Geospatial::Point, spatial: true }.merge() end |
#spatial_index(name, options = {}) ⇒ Object
create spatial index for given field www.mongodb.org/display/DOCS/Geospatial+Indexing#GeospatialIndexing-geoNearCommand
72 73 74 75 |
# File 'lib/mongoid/geospatial.rb', line 72 def spatial_index(name, = {}) spatial_fields_indexed << name index({ name => '2d' }, ) end |
#spatial_scope(field, _opts = {}) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/mongoid/geospatial.rb', line 82 def spatial_scope(field, _opts = {}) singleton_class.class_eval do # define_method(:close) do |args| define_method(:nearby) do |args| queryable.where(field.near_sphere => args) end end end |
#sphere_index(name, options = {}) ⇒ Object
77 78 79 80 |
# File 'lib/mongoid/geospatial.rb', line 77 def sphere_index(name, = {}) spatial_fields_indexed << name index({ name => '2dsphere' }, ) end |