Class: Fried::Schema::AttributesToHash
- Inherits:
-
Object
- Object
- Fried::Schema::AttributesToHash
- Includes:
- Typings
- Defined in:
- lib/fried/schema/attributes_to_hash.rb
Overview
Converts all attributes into a Hash of name => value. It calls #to_h on each value that is a DataEntity
Instance Attribute Summary collapse
-
#get_attribute ⇒ Object
Returns the value of attribute get_attribute.
Class Method Summary collapse
Instance Method Summary collapse
-
#call(schema, obj) ⇒ Hash{Symbol => Object}
Hash of attributes key => values.
-
#initialize ⇒ AttributesToHash
constructor
A new instance of AttributesToHash.
Constructor Details
#initialize ⇒ AttributesToHash
Returns a new instance of AttributesToHash.
15 16 17 |
# File 'lib/fried/schema/attributes_to_hash.rb', line 15 def initialize self.get_attribute = GetAttribute.new end |
Instance Attribute Details
#get_attribute ⇒ Object
Returns the value of attribute get_attribute.
13 14 15 |
# File 'lib/fried/schema/attributes_to_hash.rb', line 13 def get_attribute @get_attribute end |
Class Method Details
.build ⇒ Object
19 20 21 22 23 |
# File 'lib/fried/schema/attributes_to_hash.rb', line 19 def self.build new.tap do |instance| instance.get_attribute = GetAttribute.build end end |
.call(schema, obj) ⇒ Object
25 26 27 28 |
# File 'lib/fried/schema/attributes_to_hash.rb', line 25 def self.call(schema, obj) instance = build instance.(schema, obj) end |
Instance Method Details
#call(schema, obj) ⇒ Hash{Symbol => Object}
Returns hash of attributes key => values.
34 35 36 37 38 39 40 |
# File 'lib/fried/schema/attributes_to_hash.rb', line 34 def call(schema, obj) schema.each_attribute.inject({}) do |hash, attribute| value = get_attribute.(obj, attribute) hash[attribute.name] = value_to_h(value) hash end end |