module Mixture::Extensions::Attributable::ClassMethods

The class methods for attribution.

Public Instance Methods

attribute(name, options = {}) click to toggle source

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

@param name [Symbol] The name of the attribute. @param options [Hash] The options for the attribute. @return [Attribute] The new attribute.

# File lib/mixture/extensions/attributable.rb, line 17
def attribute(name, options = {})
  name = name.to_s.intern
  attr = attributes.create(name, options)
  define_method(attr.getter) {     attribute(name)    } unless
    options[:wo] || options[:write_only]
  define_method(attr.setter) { |v| attribute(name, v) } unless
    options[:ro] || options[:read_only]
  attr
end
attributes() click to toggle source

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

@see AttributeList @return [AttributeList]

# File lib/mixture/extensions/attributable.rb, line 31
def attributes
  @_attributes ||= build_attributes
end

Private Instance Methods

build_attributes() click to toggle source
# File lib/mixture/extensions/attributable.rb, line 37
def build_attributes
  available = ancestors[1..-1]
              .select { |c| c.respond_to?(:attributes) }
              .first
  parent = available ? available.attributes : nil
  AttributeList.new(parent)
end