Class: Treaty::Attribute::Validation::Base
- Inherits:
-
Object
- Object
- Treaty::Attribute::Validation::Base
- Defined in:
- lib/treaty/attribute/validation/base.rb
Overview
Base class for request and response validation.
## Purpose
Provides common interface for validation used in Treaty. Subclasses implement specific validation logic for requests and responses.
## Responsibilities
-
**Validation Interface** - Defines common validation interface
-
**Factory Pattern** - Provides class-level validate! method
## Subclasses
-
Request::Validation - Validates request data (uses Orchestrator::Request)
-
Response::Validation - Validates response data (uses Orchestrator::Response)
## Usage
Subclasses must implement:
-
‘validate!` - Performs validation and returns transformed data
Example usage:
Request::Validation.validate!(version_factory: factory, data: params)
## Factory Method
The ‘self.validate!(…)` class method provides a convenient factory pattern: “`ruby Request::Validation.validate!(version_factory: factory, data: params) # Equivalent to: Request::Validation.new(version_factory: factory).validate!(data: params) “`
## Architecture
Works with:
-
VersionFactory - Provides version information
-
Orchestrator::Base - Performs actual validation and transformation
Class Method Summary collapse
-
.validate! ⇒ Hash
Class-level factory method for validation Creates instance and calls validate!.
Instance Method Summary collapse
-
#initialize(version_factory:) ⇒ Base
constructor
Creates a new validation instance.
-
#validate! ⇒ Hash
Performs validation and transformation Must be implemented in subclasses.
Constructor Details
#initialize(version_factory:) ⇒ Base
Creates a new validation instance
58 59 60 |
# File 'lib/treaty/attribute/validation/base.rb', line 58 def initialize(version_factory:) @version_factory = version_factory end |
Class Method Details
.validate! ⇒ Hash
Class-level factory method for validation Creates instance and calls validate!
51 52 53 |
# File 'lib/treaty/attribute/validation/base.rb', line 51 def self.validate!(...) new(...).validate! end |
Instance Method Details
#validate! ⇒ Hash
Performs validation and transformation Must be implemented in subclasses
67 68 69 70 |
# File 'lib/treaty/attribute/validation/base.rb', line 67 def validate! raise Treaty::Exceptions::Validation, I18n.t("treaty.attributes.validators.nested.orchestrator.collection_not_implemented") end |