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(source, 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:

  • source (Object)

    source of the validation, to be passed to errors for better messaging.

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



18
19
20
21
22
23
24
# 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

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)


32
33
34
35
36
# File 'lib/linearly/validation.rb', line 32

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