Class: Treaty::Entity::Attribute::Validation::NestedTransformer::ArrayTransformer
- Inherits:
-
Object
- Object
- Treaty::Entity::Attribute::Validation::NestedTransformer::ArrayTransformer
- Defined in:
- lib/treaty/entity/attribute/validation/nested_transformer.rb
Overview
Transforms array with nested attributes
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
Instance Method Summary collapse
-
#initialize(attribute) ⇒ ArrayTransformer
constructor
Creates a new array transformer.
-
#transform(value, root_data = {}) ⇒ Array
Transforms array by processing each element Handles both simple arrays (:_self) and complex arrays (objects).
Constructor Details
#initialize(attribute) ⇒ ArrayTransformer
Creates a new array transformer
219 220 221 |
# File 'lib/treaty/entity/attribute/validation/nested_transformer.rb', line 219 def initialize(attribute) @attribute = attribute end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
214 215 216 |
# File 'lib/treaty/entity/attribute/validation/nested_transformer.rb', line 214 def attribute @attribute end |
Instance Method Details
#transform(value, root_data = {}) ⇒ Array
Transforms array by processing each element Handles both simple arrays (:_self) and complex arrays (objects)
229 230 231 232 233 234 235 236 237 |
# File 'lib/treaty/entity/attribute/validation/nested_transformer.rb', line 229 def transform(value, root_data = {}) value.each_with_index.map do |item, index| if simple_array? transform_simple_element(item, index, root_data) else transform_array_item(item, index, root_data) end end end |