Sha256: e70790568545e111f0d471830a6604872ca0faa06407fe94e9faf004a600797a

Contents?: true

Size: 551 Bytes

Versions: 1

Compression:

Stored size: 551 Bytes

Contents

#
# Mongoid fields extension
#
# field :foo, :delegate => {opts
#
Mongoid::Fields.option :delegate do |model, field, options|
  options = {} unless options.is_a?(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

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid-geospatial-3.9.0 lib/mongoid/geospatial/helpers/delegate.rb