Class: Treaty::Entity::Attribute::Validation::AttributeValidator
- Inherits:
-
Object
- Object
- Treaty::Entity::Attribute::Validation::AttributeValidator
- Defined in:
- lib/treaty/entity/attribute/validation/attribute_validator.rb
Overview
Validates and transforms individual attributes.
Purpose
Acts as the main interface for attribute validation and transformation. Delegates option processing to OptionOrchestrator and handles nested validation.
Responsibilities
- Schema Validation - Validates DSL definition correctness
- Value Validation - Validates runtime data values
- Value Transformation - Transforms values (defaults, etc.)
- Name Transformation - Provides target name (for
as:option) - Nested Validation - Delegates to NestedObjectValidator/NestedArrayValidator
Usage
Used by Orchestrator to validate each attribute:
validator = AttributeValidator.new(attribute)
validator.validate_schema!
validator.validate_value!(value)
transformed = validator.transform_value(value)
target_name = validator.target_name
Architecture
Delegates to:
OptionOrchestrator- Coordinates all option processorsNestedObjectValidator- Validates nested object structuresNestedArrayValidator- Validates nested array structures
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#option_orchestrator ⇒ Object
readonly
Returns the value of attribute option_orchestrator.
Instance Method Summary collapse
-
#initialize(attribute) ⇒ AttributeValidator
constructor
Creates a new attribute validator instance.
-
#target_name ⇒ Symbol
Gets the target attribute name.
-
#transform_value(value, root_data = {}) ⇒ Object
Transforms attribute value through all modifiers.
-
#transforms_name? ⇒ Boolean
Checks if attribute name is transformed.
-
#validate_required!(value) ⇒ void
Validates only the required constraint Used by nested transformers to validate presence before nested validation.
-
#validate_schema! ⇒ void
Validates the attribute schema (DSL definition).
-
#validate_type!(value) ⇒ void
Validates only the type constraint Used by nested transformers to validate types before nested validation.
-
#validate_value!(value) ⇒ void
Validates attribute value against all constraints.
Constructor Details
#initialize(attribute) ⇒ AttributeValidator
Creates a new attribute validator instance
44 45 46 47 48 49 |
# File 'lib/treaty/entity/attribute/validation/attribute_validator.rb', line 44 def initialize(attribute) @attribute = attribute @option_orchestrator = OptionOrchestrator.new(attribute) @nested_object_validator = nil @nested_array_validator = nil end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
39 40 41 |
# File 'lib/treaty/entity/attribute/validation/attribute_validator.rb', line 39 def attribute @attribute end |
#option_orchestrator ⇒ Object (readonly)
Returns the value of attribute option_orchestrator.
39 40 41 |
# File 'lib/treaty/entity/attribute/validation/attribute_validator.rb', line 39 def option_orchestrator @option_orchestrator end |
Instance Method Details
#target_name ⇒ Symbol
Gets the target attribute name
88 89 90 |
# File 'lib/treaty/entity/attribute/validation/attribute_validator.rb', line 88 def target_name option_orchestrator.target_name end |
#transform_value(value, root_data = {}) ⇒ Object
Transforms attribute value through all modifiers
74 75 76 |
# File 'lib/treaty/entity/attribute/validation/attribute_validator.rb', line 74 def transform_value(value, root_data = {}) option_orchestrator.transform_value(value, root_data) end |
#transforms_name? ⇒ Boolean
Checks if attribute name is transformed
81 82 83 |
# File 'lib/treaty/entity/attribute/validation/attribute_validator.rb', line 81 def transforms_name? option_orchestrator.transforms_name? end |
#validate_required!(value) ⇒ void
This method returns an undefined value.
Validates only the required constraint Used by nested transformers to validate presence before nested validation
109 110 111 112 |
# File 'lib/treaty/entity/attribute/validation/attribute_validator.rb', line 109 def validate_required!(value) required_processor = option_orchestrator.processor_for(:required) required_processor&.validate_value!(value) if attribute..key?(:required) end |
#validate_schema! ⇒ void
This method returns an undefined value.
Validates the attribute schema (DSL definition)
55 56 57 |
# File 'lib/treaty/entity/attribute/validation/attribute_validator.rb', line 55 def validate_schema! option_orchestrator.validate_schema! end |
#validate_type!(value) ⇒ void
This method returns an undefined value.
Validates only the type constraint Used by nested transformers to validate types before nested validation
98 99 100 101 |
# File 'lib/treaty/entity/attribute/validation/attribute_validator.rb', line 98 def validate_type!(value) type_processor = option_orchestrator.processor_for(:type) type_processor&.validate_value!(value) end |
#validate_value!(value) ⇒ void
This method returns an undefined value.
Validates attribute value against all constraints
64 65 66 67 |
# File 'lib/treaty/entity/attribute/validation/attribute_validator.rb', line 64 def validate_value!(value) option_orchestrator.validate_value!(value) validate_nested!(value) if attribute.nested? && !value.nil? end |