Class: Fried::Schema::HashToAttributes
- Inherits:
-
Object
- Object
- Fried::Schema::HashToAttributes
- Defined in:
- lib/fried/schema/hash_to_attributes.rb
Overview
Sets all attributes based on hash
Instance Attribute Summary collapse
-
#set_attribute ⇒ Object
Returns the value of attribute set_attribute.
Class Method Summary collapse
Instance Method Summary collapse
- #call(schema, attributes, obj) ⇒ void
-
#initialize ⇒ HashToAttributes
constructor
A new instance of HashToAttributes.
Constructor Details
#initialize ⇒ HashToAttributes
Returns a new instance of HashToAttributes.
9 10 11 |
# File 'lib/fried/schema/hash_to_attributes.rb', line 9 def initialize self.set_attribute = SetAttribute.new end |
Instance Attribute Details
#set_attribute ⇒ Object
Returns the value of attribute set_attribute.
7 8 9 |
# File 'lib/fried/schema/hash_to_attributes.rb', line 7 def set_attribute @set_attribute end |
Class Method Details
.build ⇒ Object
13 14 15 16 17 |
# File 'lib/fried/schema/hash_to_attributes.rb', line 13 def self.build new.tap do |instance| instance.set_attribute = SetAttribute.build end end |
.call(schema, attributes, obj) ⇒ Object
19 20 21 22 |
# File 'lib/fried/schema/hash_to_attributes.rb', line 19 def self.call(schema, attributes, obj) instance = build instance.(schema, attributes, obj) end |
Instance Method Details
#call(schema, attributes, obj) ⇒ void
This method returns an undefined value.
29 30 31 32 33 34 35 |
# File 'lib/fried/schema/hash_to_attributes.rb', line 29 def call(schema, attributes, obj) schema.each_attribute do |attribute| next unless attributes.has_key?(attribute.name) value = attributes[attribute.name] set_attribute.(obj, attribute, value) end end |