Module: Lean::Attributes::ClassMethods

Defined in:
lib/lean-attributes/attributes/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name, type, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/lean-attributes/attributes/class_methods.rb', line 6

def attribute(name, type, options = {})
  attribute = Attribute.new(
    default:  options[:default],
    name:     name,
    type:     type
  )

  class_eval(attribute.coercion_method, __FILE__, __LINE__ + 1)
  class_eval(attribute.getter_method,   __FILE__, __LINE__ + 1)
  class_eval(attribute.setter_method,   __FILE__, __LINE__ + 1)

  attribute
end