Class: Treaty::Attribute::Validation::NestedTransformer
- Inherits:
-
Object
- Object
- Treaty::Attribute::Validation::NestedTransformer
- Defined in:
- lib/treaty/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) ⇒ 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
17 18 19 |
# File 'lib/treaty/attribute/validation/nested_transformer.rb', line 17 def initialize(attribute) @attribute = attribute end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
12 13 14 |
# File 'lib/treaty/attribute/validation/nested_transformer.rb', line 12 def attribute @attribute end |
Instance Method Details
#transform(value) ⇒ Object
Transforms nested attribute value (object or array) Returns original value if nil or not nested
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/treaty/attribute/validation/nested_transformer.rb', line 26 def transform(value) return value if value.nil? case attribute.type when :object transform_object(value) when :array transform_array(value) else value end end |