Class: Treaty::Entity::Attribute::Validation::NestedTransformer::ArrayTransformer

Inherits:
Object
  • Object
show all
Defined in:
lib/treaty/entity/attribute/validation/nested_transformer.rb

Overview

Transforms array with nested attributes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ ArrayTransformer

Creates a new array transformer

Parameters:

  • The array-type attribute



219
220
221
# File 'lib/treaty/entity/attribute/validation/nested_transformer.rb', line 219

def initialize(attribute)
  @attribute = attribute
end

Instance Attribute Details

#attributeObject (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)

Parameters:

  • The source array

  • (defaults to: {})

    Full raw data from root level (for computed modifier)

Returns:

  • Transformed array



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