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

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

Overview

Transforms object (hash) with nested attributes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ ObjectTransformer

Creates a new object transformer

Parameters:



74
75
76
# File 'lib/treaty/entity/attribute/validation/nested_transformer.rb', line 74

def initialize(attribute)
  @attribute = attribute
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



69
70
71
# File 'lib/treaty/entity/attribute/validation/nested_transformer.rb', line 69

def attribute
  @attribute
end

Instance Method Details

#transform(value, root_data = {}) ⇒ Hash

Transforms hash by processing all nested attributes

Parameters:

  • value (Hash)

    The source hash

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

    Full raw data from root level (for computed modifier)

Returns:

  • (Hash)

    Transformed hash with processed attributes



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/treaty/entity/attribute/validation/nested_transformer.rb', line 83

def transform(value, root_data = {})
  transformed = {}

  attribute.collection_of_attributes.each do |nested_attribute|
    # Check if conditional (if/unless option) - skip attribute if condition evaluates to skip
    next unless should_process_attribute?(nested_attribute, value)

    process_attribute(nested_attribute, value, transformed, root_data)
  end

  transformed
end