Class: Treaty::Entity::Attribute::Validation::NestedTransformer
- Inherits:
-
Object
- Object
- Treaty::Entity::Attribute::Validation::NestedTransformer
- Defined in:
- lib/treaty/entity/attribute/validation/nested_transformer.rb
Overview
Handles transformation of nested attributes (objects and arrays). Extracted from Orchestrator::Base to reduce complexity.
Defined Under Namespace
Classes: ArrayTransformer, ObjectTransformer
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
Instance Method Summary collapse
-
#initialize(attribute) ⇒ NestedTransformer
constructor
Creates a new nested transformer.
-
#transform(value, root_data = {}) ⇒ Object
Transforms nested attribute value (object or array) Returns original value if nil or not nested.
Constructor Details
#initialize(attribute) ⇒ NestedTransformer
Creates a new nested transformer
18 19 20 |
# File 'lib/treaty/entity/attribute/validation/nested_transformer.rb', line 18 def initialize(attribute) @attribute = attribute end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
13 14 15 |
# File 'lib/treaty/entity/attribute/validation/nested_transformer.rb', line 13 def attribute @attribute end |
Instance Method Details
#transform(value, root_data = {}) ⇒ Object
Transforms nested attribute value (object or array) Returns original value if nil or not nested
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/treaty/entity/attribute/validation/nested_transformer.rb', line 28 def transform(value, root_data = {}) return value if value.nil? case attribute.type when :object transform_object(value, root_data) when :array transform_array(value, root_data) else value end end |