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.
24 25 26 27 28 |
# File 'lib/mixture/attribute.rb', line 24 def initialize(name, list, = {}) @name = name @list = list @options = end |
Instance Attribute Details
#getter ⇒ Symbol (readonly)
The getter method for this attribute.
56 57 58 |
# File 'lib/mixture/attribute.rb', line 56 def getter @name end |
#ivar ⇒ Symbol (readonly)
The instance variable for this attribute.
46 47 48 |
# File 'lib/mixture/attribute.rb', line 46 def ivar @_ivar ||= :"@#{@name}" end |
#name ⇒ Symbol (readonly)
The name of the attribute.
10 11 12 |
# File 'lib/mixture/attribute.rb', line 10 def name @name end |
#options ⇒ Hash (readonly)
The options for the attribute. This is mainly used for coercion and validation.
16 17 18 |
# File 'lib/mixture/attribute.rb', line 16 def @options end |
#setter ⇒ Symbol (readonly)
The setter method for this attribute.
66 67 68 |
# File 'lib/mixture/attribute.rb', line 66 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.
36 37 38 |
# File 'lib/mixture/attribute.rb', line 36 def update(value) @list.callbacks[:update].inject(value) { |a, e| e.call(self, a) } end |