class Fried::Schema::HashToAttributes
Sets all attributes based on hash
Attributes
set_attribute[RW]
Public Class Methods
build()
click to toggle source
# 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)
click to toggle source
# File lib/fried/schema/hash_to_attributes.rb, line 19 def self.call(schema, attributes, obj) instance = build instance.(schema, attributes, obj) end
new()
click to toggle source
# File lib/fried/schema/hash_to_attributes.rb, line 9 def initialize self.set_attribute = SetAttribute.new end
Public Instance Methods
call(schema, attributes, obj)
click to toggle source
@param schema [Definition] @param attributes [Hash{Symbol => Object}] @param obj [::Fried::Schema::Struct] an instance of a class including
{::Fried::Schema::Struct}
@return [void]
# 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