Class: Flows::Contract::Tuple
- Inherits:
-
Flows::Contract
- Object
- Flows::Contract
- Flows::Contract::Tuple
- Defined in:
- lib/flows/contract/tuple.rb
Overview
Makes a contract fixed size array.
Underlying contracts' transformations are applied.
Constant Summary collapse
Instance Method Summary collapse
- #check!(other) ⇒ Object
-
#initialize(*contracts) ⇒ Tuple
constructor
A new instance of Tuple.
- #transform!(other) ⇒ Object
Methods inherited from Flows::Contract
#===, #check, make, #to_proc, #transform
Constructor Details
#initialize(*contracts) ⇒ Tuple
Returns a new instance of Tuple.
19 20 21 |
# File 'lib/flows/contract/tuple.rb', line 19 def initialize(*contracts) @contracts = contracts.map(&method(:to_contract)) end |
Instance Method Details
#check!(other) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/flows/contract/tuple.rb', line 24 def check!(other) ARRAY_CONTRACT.check!(other) check_length(other) errors = collect_errors(other) return true if errors.empty? raise Error.new(other, render_errors(other, errors)) end |
#transform!(other) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/flows/contract/tuple.rb', line 35 def transform!(other) check!(other) other.map.with_index do |elem, index| @contracts[index].transform!(elem) end end |