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

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ NestedTransformer

Creates a new nested transformer

Parameters:



18
19
20
# File 'lib/treaty/entity/attribute/validation/nested_transformer.rb', line 18

def initialize(attribute)
  @attribute = attribute
end

Instance Attribute Details

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

Parameters:

  • value (Object)

    The value to transform

  • root_data (Hash) (defaults to: {})

    Full raw data from root level (for computed modifier)

Returns:

  • (Object)

    Transformed value



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