Class: Fried::Schema::HashToAttributes

Inherits:
Object
  • Object
show all
Defined in:
lib/fried/schema/hash_to_attributes.rb

Overview

Sets all attributes based on hash

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHashToAttributes

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_attributeObject

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

.buildObject



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.

Parameters:



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