Class: BloodContracts::Core::Contract

Inherits:
Object
  • Object
show all
Defined in:
lib/blood_contracts/core/contract.rb

Overview

Meta refinement type, represents contract built upon input and output types

Class Method Summary collapse

Class Method Details

.new(*args) ⇒ BC::Refined

Metaprogramming around constructor Turns input types into a contract

Parameters:

  • expectations (Hash<BC::Refined, BC::Refined>)

    about possible data input expressed in form of BC::Refined types

Returns:

  • (BC::Refined)

    contract for data validation in form of BC::Refined class



14
15
16
17
18
19
20
21
22
23
# File 'lib/blood_contracts/core/contract.rb', line 14

def new(*args)
  input, output =
    if (opts = args.last).is_a?(Hash)
      accumulate_contract(opts)
    else
      _validate_args!(args)
      args
    end
  BC::Pipe.new(input, output, names: %i[input output])
end