Module: Mongoid::Geospatial::ClassMethods

Defined in:
lib/mongoid_geospatial/geospatial.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

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



44
45
46
# File 'lib/mongoid_geospatial/geospatial.rb', line 44

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



52
53
54
55
# File 'lib/mongoid_geospatial/geospatial.rb', line 52

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