Module: Mongoid::Geospatial::ClassMethods
- Defined in:
- lib/mongoid_geospatial/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
44 45 46 |
# File 'lib/mongoid_geospatial/geospatial.rb', line 44 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
52 53 54 55 |
# File 'lib/mongoid_geospatial/geospatial.rb', line 52 def spatial_index name, = {} self.spatial_fields_indexed << name index({name => '2d'}, ) end |
#spatial_scope(field, opts = {}) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/mongoid_geospatial/geospatial.rb', line 62 def spatial_scope field, opts = {} self.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
57 58 59 60 |
# File 'lib/mongoid_geospatial/geospatial.rb', line 57 def sphere_index name, = {} self.spatial_fields_indexed << name index({name => '2dsphere'}, ) end |