class Linearly::Validation

{Validation} provides a way to check inputs and outputs against a set of per-field expectations. @abstract

Attributes

expectations[R]

Wrapped expectations

@return [Hash<Symbol, Expectation>] @api private

Public Class Methods

new(source, expectations) click to toggle source

Constructor for a {Validation}

@param source [Object] source of the validation, to be passed to errors

for better messaging.

@param expectations [Hash<Symbol, Expectation>] a hash of per-field

expectations. An expectation can be +true+ (just checking for field
presence), a class name (checking for value type) or a +Proc+
taking a value and returning a +Boolean+.

@api private

# File lib/linearly/validation.rb, line 18
def initialize(source, expectations)
  @source = source
  @expectations =
    expectations
    .map { |key, expectation| [key, Expectation.to_proc(expectation)] }
    .to_h
end

Public Instance Methods

call(state) click to toggle source

Call validation with a {State}

@param state [Statefully::State]

@return [Statefully::State] @api private

# File lib/linearly/validation.rb, line 32
def call(state)
  Validator
    .new(@source, expectations, state)
    .validate(error_class)
end