Sha256: 238b3dbf6be3e993e7a26e6d7dcc56cddadff8e6b7606f5fa5bc70fa9ddfac14

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Extensions #:nodoc:
    module Symbol #:nodoc:

      # return a class that will accept a value to convert the query correctly for near
      #
      # @param [Symbol] calc This accepts :sphere
      #
      # @return [Criterion::NearSpatial]

      def near(calc = :flat)
        Criterion::NearSpatial.new(:operator => get_op('near',calc), :key => self)
      end

      # alias for self.near(:sphere)
      #
      # @return [Criterion::NearSpatial]
      def near_sphere
        self.near(:sphere)
      end

      # @param [Symbol] shape :box,:polygon,:center,:center_sphere
      #
      # @return [Criterion::WithinSpatial]
      def within(shape)
        shape = get_op(:center,:sphere) if shape == :center_sphere
        Criterion::WithinSpatial.new(:operator => shape.to_s , :key => self)
      end

      private

      def get_op operator, calc
        if calc.to_sym == :sphere
          "#{operator}Sphere"
        else
          operator.to_s
        end
      end

    end
  end
end


::Symbol.__send__(:include, Mongoid::Extensions::Symbol)

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
mongoid_location-0.3.5 lib/mongoid_location/extensions/symbol.rb
mongoid_location-0.3.3 lib/mongoid_location/extensions/symbol.rb
mongoid_location-0.3.2 lib/mongoid_location/extensions/symbol.rb
mongoid_geospatial-2.0.0 lib/mongoid_geospatial/extensions/symbol.rb
mongoid_geospatial-1.0.0 lib/mongoid_geospatial/extensions/symbol.rb