Class: Linearly::Validation Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/linearly/validation.rb

Overview

This class is abstract.

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

Direct Known Subclasses

Inputs, Outputs

Defined Under Namespace

Modules: Expectation Classes: Failure, Inputs, Outputs

Instance Method Summary collapse

Constructor Details

#initialize(expectations) ⇒ Validation

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Constructor for a Linearly::Validation

Parameters:

  • 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.



16
17
18
19
20
21
# File 'lib/linearly/validation.rb', line 16

def initialize(expectations)
  @expectations =
    expectations
    .map { |key, expectation| [key, Expectation.to_proc(expectation)] }
    .to_h
end

Instance Method Details

#call(state) ⇒ Statefully::State

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Call validation with a State

Parameters:

  • state (Statefully::State)

Returns:

  • (Statefully::State)


29
30
31
32
33
# File 'lib/linearly/validation.rb', line 29

def call(state)
  Validator
    .new(expectations, state)
    .validate(error_class)
end