module Mongoo::Attributes::DescribeDsl

Public Instance Methods

attribute(name, opts={}) click to toggle source
# File lib/mongoo/attributes/describe_dsl.rb, line 4
def attribute(name, opts={})
  raise ArgumentError.new("missing :type") unless opts[:type]
  @klass.attributes[name.to_s] = opts
  true
end

Protected Instance Methods

define_attribute_methods() click to toggle source
# File lib/mongoo/attributes/describe_dsl.rb, line 10
def define_attribute_methods
  @klass.attributes_tree(only_definable: true).each do |name, val|
    if val.is_a?(Hash)
      blk = Proc.new { Mongoo::AttributeProxy.new(val, [name], self) }
      @klass.send(:define_method, name, &blk)
    else
      blk = Proc.new { get(name) }
      @klass.send(:define_method, name, &blk)
      blk = Proc.new { |val| set(name, val) }
      @klass.send(:define_method, "#{name}=", &blk)
    end
  end
end