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

Inherits:
Object
  • Object
show all
Defined in:
lib/treaty/entity/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:

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



59
60
61
# File 'lib/treaty/entity/attribute/validation/base.rb', line 59

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



52
53
54
# File 'lib/treaty/entity/attribute/validation/base.rb', line 52

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:



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

def validate!
  raise Treaty::Exceptions::Validation,
        I18n.t("treaty.attributes.validators.nested.orchestrator.collection_not_implemented")
end