Module: Mixture::Extensions::Attributable::ClassMethods

Defined in:
lib/mixture/extensions/attributable.rb

Overview

The class methods for attribution.

Instance Method Summary collapse

Instance Method Details

#attribute(name, options = {}) ⇒ Attribute

Defines an attribute. Defines the getter and the setter for for the attribute, the getter and setter alias to the #attribute.

Parameters:

  • name (Symbol)

    The name of the attribute.

  • options (Hash) (defaults to: {})

    The options for the attribute.

Returns:


16
17
18
19
20
21
22
# File 'lib/mixture/extensions/attributable.rb', line 16

def attribute(name, options = {})
  name = name.to_s.intern
  attr = attributes.create(name, options)
  define_method(attr.getter) {     attribute(name)    }
  define_method(attr.setter) { |v| attribute(name, v) }
  attr
end

#attributesAttributeList

The attribute list. Acts as a hash for the attributes.

Returns:

See Also:


28
29
30
# File 'lib/mixture/extensions/attributable.rb', line 28

def attributes
  @_attributes ||= AttributeList.new
end