Class: Treaty::Entity::Attribute::Validation::NestedTransformer::ObjectTransformer
- Inherits:
-
Object
- Object
- Treaty::Entity::Attribute::Validation::NestedTransformer::ObjectTransformer
- Defined in:
- lib/treaty/entity/attribute/validation/nested_transformer.rb
Overview
Transforms object (hash) with nested attributes
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
Instance Method Summary collapse
-
#initialize(attribute) ⇒ ObjectTransformer
constructor
Creates a new object transformer.
-
#transform(value, root_data = {}) ⇒ Hash
Transforms hash by processing all nested attributes.
Constructor Details
#initialize(attribute) ⇒ ObjectTransformer
Creates a new object transformer
74 75 76 |
# File 'lib/treaty/entity/attribute/validation/nested_transformer.rb', line 74 def initialize(attribute) @attribute = attribute end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
69 70 71 |
# File 'lib/treaty/entity/attribute/validation/nested_transformer.rb', line 69 def attribute @attribute end |
Instance Method Details
#transform(value, root_data = {}) ⇒ Hash
Transforms hash by processing all nested attributes
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/treaty/entity/attribute/validation/nested_transformer.rb', line 83 def transform(value, root_data = {}) transformed = {} attribute.collection_of_attributes.each do |nested_attribute| # Check if conditional (if/unless option) - skip attribute if condition evaluates to skip next unless should_process_attribute?(nested_attribute, value) process_attribute(nested_attribute, value, transformed, root_data) end transformed end |