Class: Treaty::Attribute::Validation::Base

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

  1. **Validation Interface** - Defines common validation interface

  2. **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

Instance Method Summary collapse

Constructor Details

#initialize(version_factory:) ⇒ Base

Creates a new validation instance

Parameters:

  • version_factory (VersionFactory)

    Factory containing version information



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!

Parameters:

  • args (Hash)

    Arguments passed to initialize and validate!

Returns:

  • (Hash)

    Validated and transformed data



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

Returns:

  • (Hash)

    Validated and transformed data

Raises:



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