Module: Mixture::Extensions::Attributable::ClassMethods
- Defined in:
- lib/mixture/extensions/attributable.rb
Overview
The class methods for attribution.
Instance Method Summary collapse
-
#attribute(name, options = {}) ⇒ Attribute
Defines an attribute.
-
#attributes ⇒ AttributeList
The attribute list.
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.
17 18 19 20 21 22 23 24 25 |
# File 'lib/mixture/extensions/attributable.rb', line 17 def attribute(name, = {}) name = name.to_s.intern attr = attributes.create(name, ) define_method(attr.getter) { attribute(name) } unless [:wo] || [:write_only] define_method(attr.setter) { |v| attribute(name, v) } unless [:ro] || [:read_only] attr end |
#attributes ⇒ AttributeList
The attribute list. Acts as a hash for the attributes.
31 32 33 34 35 36 37 38 |
# File 'lib/mixture/extensions/attributable.rb', line 31 def attributes return @_attributes if @_attributes available = ancestors[1..-1] .select { |c| c.respond_to?(:attributes) } .first parent = available ? available.attributes : nil @_attributes = AttributeList.new(parent) end |