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
45 46 47 |
# File 'lib/mongoid_geospatial/geospatial.rb', line 45 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
53 54 55 56 |
# File 'lib/mongoid_geospatial/geospatial.rb', line 53 def spatial_index name, = {} self.spatial_fields_indexed << name index({ name => '2d' }, ) end |
#spatial_scope(field, opts = {}) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/mongoid_geospatial/geospatial.rb', line 63 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
58 59 60 61 |
# File 'lib/mongoid_geospatial/geospatial.rb', line 58 def sphere_index(name, = {}) self.spatial_fields_indexed << name index({ name => '2dsphere' }, ) end |