Module: Mongoid::Geospatial::ClassMethods

Defined in:
lib/mongoid/geospatial.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#geo_field(name, options = {}) ⇒ Object



63
64
65
66
# File 'lib/mongoid/geospatial.rb', line 63

def geo_field(name, options = {})
  field name, { type: Mongoid::Geospatial::Point,
                spatial: true }.merge(options)
end

#spatial_index(name, options = {}) ⇒ Object

Parameters:

  • name (String, Symbol)
  • options (Hash) (defaults to: {})

    options for spatial_index



72
73
74
75
# File 'lib/mongoid/geospatial.rb', line 72

def spatial_index(name, options = {})
  spatial_fields_indexed << name
  index({ name => '2d' }, options)
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, options = {})
  spatial_fields_indexed << name
  index({ name => '2dsphere' }, options)
end