Class: Treaty::Entity::Attribute::Validation::Orchestrator::Base
- Inherits:
-
Object
- Object
- Treaty::Entity::Attribute::Validation::Orchestrator::Base
- Defined in:
- lib/treaty/entity/attribute/validation/orchestrator/base.rb
Overview
Base orchestrator for validating and transforming data according to treaty definitions.
Purpose
Coordinates the validation and transformation of request/response data for a specific API version. Processes all attributes, applying validations and transformations defined in the treaty DSL.
Responsibilities
- Attribute Processing - Iterates through all defined attributes
- Attribute Validation - Validates each attribute's value
- Data Transformation - Transforms values (defaults, renaming)
- Nested Handling - Delegates nested structures to NestedTransformer
- Result Assembly - Builds final transformed data structure
Usage
Subclasses must implement:
collection_of_attributes- Returns attributes for this context (request/response)
Example:
orchestrator = Request::Orchestrator.new(version_factory: factory, data: params)
validated_data = orchestrator.validate!
Special Case: object :_self
- Normal object:
{ object_name: { ... } } - Self object (
:_self): Attributes merged directly into parent
Architecture
Uses:
AttributeValidator- Validates individual attributesNestedTransformer- Handles nested objects and arrays
The design separates concerns:
- Orchestrator: High-level flow and attribute iteration
- Validator: Individual attribute validation
- Transformer: Nested structure transformation
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#version_factory ⇒ Object
readonly
Returns the value of attribute version_factory.
Class Method Summary collapse
-
.validate! ⇒ Hash
Class-level factory method for validation Creates instance and calls validate!.
Instance Method Summary collapse
-
#initialize(version_factory:, data: {}) ⇒ Base
constructor
Creates a new orchestrator instance.
-
#validate! ⇒ Hash
Validates and transforms all attributes Iterates through attributes, processes them, handles :_self objects Skips attributes with false conditional (if/unless option).
Constructor Details
#initialize(version_factory:, data: {}) ⇒ Base
Creates a new orchestrator instance
67 68 69 70 |
# File 'lib/treaty/entity/attribute/validation/orchestrator/base.rb', line 67 def initialize(version_factory:, data: {}) @version_factory = version_factory @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
52 53 54 |
# File 'lib/treaty/entity/attribute/validation/orchestrator/base.rb', line 52 def data @data end |
#version_factory ⇒ Object (readonly)
Returns the value of attribute version_factory.
52 53 54 |
# File 'lib/treaty/entity/attribute/validation/orchestrator/base.rb', line 52 def version_factory @version_factory end |
Class Method Details
.validate! ⇒ Hash
Class-level factory method for validation Creates instance and calls validate!
59 60 61 |
# File 'lib/treaty/entity/attribute/validation/orchestrator/base.rb', line 59 def self.validate!(...) new(...).validate! end |
Instance Method Details
#validate! ⇒ Hash
Validates and transforms all attributes Iterates through attributes, processes them, handles :_self objects Skips attributes with false conditional (if/unless option)
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/treaty/entity/attribute/validation/orchestrator/base.rb', line 77 def validate! # rubocop:disable Metrics/MethodLength transformed_data = {} collection_of_attributes.each do |attribute| # Check if conditional (if/unless option) - skip attribute if condition evaluates to skip next unless should_process_attribute?(attribute) transformed_value = validate_and_transform_attribute!(attribute) if attribute.name == SELF_OBJECT && attribute.type == :object # For object :_self, merge nested attributes to root transformed_data.merge!(transformed_value) else transformed_data[attribute.name] = transformed_value end end transformed_data end |