Class: ActiveRecord::AttributeView
- Inherits:
-
Object
- Object
- ActiveRecord::AttributeView
- Defined in:
- lib/active_record/attribute_views.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
Instance Method Summary collapse
- #get(record) ⇒ Object
-
#initialize(*attributes) ⇒ AttributeView
constructor
A new instance of AttributeView.
- #load(*values) ⇒ Object
- #parse(input) ⇒ Object
- #set(record, input) ⇒ Object
Constructor Details
#initialize(*attributes) ⇒ AttributeView
Returns a new instance of AttributeView.
5 6 7 |
# File 'lib/active_record/attribute_views.rb', line 5 def initialize(*attributes) self.attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/active_record/attribute_views.rb', line 3 def attributes @attributes end |
Instance Method Details
#get(record) ⇒ Object
9 10 11 |
# File 'lib/active_record/attribute_views.rb', line 9 def get(record) load(*attributes.map { |attribute| record.send(attribute) }) end |
#load(*values) ⇒ Object
13 14 15 |
# File 'lib/active_record/attribute_views.rb', line 13 def load(*values) raise NoMethodError, "Please implement the `load' method on your view class" end |
#parse(input) ⇒ Object
22 23 24 |
# File 'lib/active_record/attribute_views.rb', line 22 def parse(input) raise NoMethodError, "Please implement the `parse' method on your view class" end |
#set(record, input) ⇒ Object
17 18 19 20 |
# File 'lib/active_record/attribute_views.rb', line 17 def set(record, input) parsed = Array(parse(input)) record.attributes = Hash[*attributes.zip(parsed).flatten] end |