Sha256: 3ced506f0db6e3f2efe9deca570715b4a3359d0edfbe56f2ca29ab4cde2fadd2

Contents?: true

Size: 619 Bytes

Versions: 6

Compression:

Stored size: 619 Bytes

Contents

Mongoid::Fields.option :delegate do |model, field, options|
  options = {} unless options.kind_of?(Hash)
  x_meth = options[:x] || :x
  y_meth = options[:y] || :y

  model.instance_eval do
    define_method x_meth do self[field.name][0]; end
    define_method y_meth do self[field.name][1]; end

    define_method "#{x_meth}=" do |arg|
      self[field.name][0] = arg
    end

    define_method "#{y_meth}=" do |arg|
      self[field.name][1] = arg
    end

    # model.class_eval do
    #   define_method "close_to" do |*args|
    #     queriable.where(field.name.near_sphere => *args)
    #   end
    # end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mongoid_geospatial-2.8.2 lib/mongoid_geospatial/helpers/delegate.rb
mongoid_geospatial-2.8.1 lib/mongoid_geospatial/helpers/delegate.rb
mongoid_geospatial-2.8.0 lib/mongoid_geospatial/helpers/delegate.rb
mongoid_geospatial-2.7.2 lib/mongoid_geospatial/helpers/delegate.rb
mongoid_geospatial-2.7.1 lib/mongoid_geospatial/helpers/delegate.rb
mongoid_geospatial-2.7.0 lib/mongoid_geospatial/helpers/delegate.rb