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

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

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ NestedTransformer

Creates a new nested transformer

Parameters:



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

def initialize(attribute)
  @attribute = attribute
end

Instance Attribute Details

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

Parameters:

  • value (Object)

    The value to transform

Returns:

  • (Object)

    Transformed value



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