Sha256: 55da482e77084b38fffe4f0006320070b5866c801e42e7de580714b755429975

Contents?: true

Size: 451 Bytes

Versions: 7

Compression:

Stored size: 451 Bytes

Contents

#require 'ostruct'

Mongoid::Fields.option :spatial do |model,field,options|
  options = {} unless options.kind_of?(Hash)
  lat_meth = options[:lat] || :lat
  lng_meth = options[:lng] || :lng
  model.class_eval do
    self.spatial_fields ||= []
    self.spatial_fields << field.name.to_sym if self.spatial_fields.kind_of? Array

    define_method "distance_from_#{field.name}" do |*args|
      self.distance_from(field.name, *args)
    end

  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
mongoid_location-0.3.5 lib/mongoid_location/field_option.rb
mongoid_location-0.3.3 lib/mongoid_location/field_option.rb
mongoid_location-0.3.2 lib/mongoid_location/field_option.rb
mongoid_geospatial-2.0.0 lib/mongoid_geospatial/field_option.rb
mongoid_geospatial-1.0.0 lib/mongoid_geospatial/field_option.rb
mongoid_geospatial-1.0.0rc1 lib/mongoid_geospatial/field_option.rb
mongoid_geospatial-1.0.0rc0 lib/mongoid_geospatial/field_option.rb