Module: Plumbing::Pipeline::Contracts

Defined in:
lib/plumbing/pipeline/contracts.rb

Overview

Validate input and output data with pre and post conditions or [Dry::Validation::Contract]s

Defined Under Namespace

Classes: ConditionValidator

Instance Method Summary collapse

Instance Method Details

#post_condition(name) {|Object| ... } ⇒ Object

Parameters:

  • name (Symbol)

    the name of the postcondition

  • &validator (Block)

    a block that returns a boolean value - true to accept the input, false to reject it

Yields:

  • (Object)

    output the output data to be validated

Yield Returns:

  • (Boolean)

    true to accept the output, false to reject it



22
23
24
# File 'lib/plumbing/pipeline/contracts.rb', line 22

def post_condition name, &validator
  post_conditions << ConditionValidator.new(name.to_s, validator)
end

#pre_condition(name) {|Object| ... } ⇒ Object

Parameters:

  • name (Symbol)

    the name of the precondition

  • &validator (Block)

    a block that returns a boolean value - true to accept the input, false to reject it

Yields:

  • (Object)

    input the input data to be validated

Yield Returns:

  • (Boolean)

    true to accept the input, false to reject it



9
10
11
# File 'lib/plumbing/pipeline/contracts.rb', line 9

def pre_condition name, &validator
  pre_conditions << ConditionValidator.new(name.to_s, validator)
end

#validate_with(contract_class) ⇒ Object

Parameters:

  • contract_class (String)

    the class name of the [Dry::Validation::Contract] that will be used to validate the input data



14
15
16
# File 'lib/plumbing/pipeline/contracts.rb', line 14

def validate_with contract_class
  @validation_contract = contract_class
end