class Mixture::Attribute

An attribute for a mixture object.

Attributes

name[R]

The name of the attribute.

@return [Symbol]

options[R]

The options for the attribute. This is mainly used for coercion and validation.

@return [Hash]

Public Class Methods

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

Initialize the attribute.

@param name [Symbol] The name of the attribute. @param list [AttributeList] The attribute list this attribute is

a part of.

@param options [Hash] The optiosn for the attribute.

# File lib/mixture/attribute.rb, line 24
def initialize(name, list, options = {})
  @name = name
  @list = list
  @options = options
end

Public Instance Methods

getter() click to toggle source

@!attribute [r] getter The getter method for this attribute.

@example Retrieve the getter.

attribute.getter # => :name

@return [Symbol]

# File lib/mixture/attribute.rb, line 56
def getter
  @name
end
ivar() click to toggle source

@!attribute [r] ivar The instance variable for this attribute.

@example Retrieve the instance variable.

attribute.ivar # => :@name

@return [Symbol]

# File lib/mixture/attribute.rb, line 46
def ivar
  @_ivar ||= :"@#{@name}"
end
setter() click to toggle source

@!attribute [r] setter The setter method for this attribute.

@example Retrieve the setter.

attribute.setter # :name=

@return [Symbol]

# File lib/mixture/attribute.rb, line 66
def setter
  @_setter ||= :"#{@name}="
end
update(value) click to toggle source

Update the attribute with the given value. It runs the value through the callbacks, and returns a new value given by the callbacks.

@param value [Object] The new value. @return [Object] The new new value.

# File lib/mixture/attribute.rb, line 36
def update(value)
  @list.callbacks[:update].inject(value) { |a, e| e.call(self, a) }
end