Sha256: df6edd5e97f3eb7721327715296efebf7e8d54c34d7052bfb26e83ff39db27b7

Contents?: true

Size: 763 Bytes

Versions: 2

Compression:

Stored size: 763 Bytes

Contents

module Mongoid
  module Spacial
    module Document
      extend ActiveSupport::Concern

      included do
        attr_accessor :geo
        cattr_accessor :spacial_fields, :spacial_fields_indexed
        @@spacial_fields = []
        @@spacial_fields_indexed = []
      end

      module ClassMethods #:nodoc:
        # create spacial index for given field
        # @param [String,Symbol] name
        # @param [Hash] options options for spacial_index
        def spacial_index name, *options
          self.spacial_fields_indexed << name
          index [[ name, Mongo::GEO2D ]], *options
        end
      end

      def distance_from(key,p2, opts = {})
        p1 = self.send(key)
        Mongoid::Spacial.distance(p1, p2, opts)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
sig_mongoid_spacial-0.2.17 lib/mongoid_spacial/spacial/document.rb
cb_mongoid_spacial-0.2.16 lib/mongoid_spacial/spacial/document.rb