Class: Mixture::Attribute
- Inherits:
-
Object
- Object
- Mixture::Attribute
- Defined in:
- lib/mixture/attribute.rb
Overview
An attribute for a mixture object.
Instance Attribute Summary collapse
-
#getter ⇒ Symbol
readonly
The getter method for this attribute.
-
#ivar ⇒ Symbol
readonly
The instance variable for this attribute.
-
#name ⇒ Symbol
readonly
The name of the attribute.
-
#options ⇒ Hash
readonly
The options for the attribute.
-
#setter ⇒ Symbol
readonly
The setter method for this attribute.
Instance Method Summary collapse
-
#initialize(name, list, options = {}) ⇒ Attribute
constructor
Initialize the attribute.
-
#update(value) ⇒ Object
Update the attribute with the given value.
Constructor Details
#initialize(name, list, options = {}) ⇒ Attribute
Initialize the attribute.
23 24 25 26 27 |
# File 'lib/mixture/attribute.rb', line 23 def initialize(name, list, = {}) @name = name @list = list = end |
Instance Attribute Details
#getter ⇒ Symbol (readonly)
The getter method for this attribute.
55 56 57 |
# File 'lib/mixture/attribute.rb', line 55 def getter @name end |
#ivar ⇒ Symbol (readonly)
The instance variable for this attribute.
45 46 47 |
# File 'lib/mixture/attribute.rb', line 45 def ivar @_ivar ||= :"@#{@name}" end |
#name ⇒ Symbol (readonly)
The name of the attribute.
9 10 11 |
# File 'lib/mixture/attribute.rb', line 9 def name @name end |
#options ⇒ Hash (readonly)
The options for the attribute. This is mainly used for coercion and validation.
15 16 17 |
# File 'lib/mixture/attribute.rb', line 15 def end |
#setter ⇒ Symbol (readonly)
The setter method for this attribute.
65 66 67 |
# File 'lib/mixture/attribute.rb', line 65 def setter @_setter ||= :"#{@name}=" end |
Instance Method Details
#update(value) ⇒ Object
Update the attribute with the given value. It runs the value through the callbacks, and returns a new value given by the callbacks.
35 36 37 |
# File 'lib/mixture/attribute.rb', line 35 def update(value) @list.callbacks[:update].inject(value) { |a, e| e.call(self, a) } end |