Class: Flows::Contract::Array
- Inherits:
-
Flows::Contract
- Object
- Flows::Contract
- Flows::Contract::Array
- Defined in:
- lib/flows/contract/array.rb
Overview
Makes a contract for Array from contract for array's element.
If underlying contract has transformation - each array element will be transformed.
Constant Summary collapse
- CHECK_LIMIT =
Stop search for a new type mismatch in elements if CHECK_LIMIT errors already found.
10
- ARRAY_CONTRACT =
CaseEq.new(::Array)
Instance Method Summary collapse
- #check!(other) ⇒ Object
-
#initialize(element_contract) ⇒ Array
constructor
A new instance of Array.
- #transform!(other) ⇒ Object
Methods inherited from Flows::Contract
#===, #check, make, #to_proc, #transform
Constructor Details
#initialize(element_contract) ⇒ Array
Returns a new instance of Array.
24 25 26 |
# File 'lib/flows/contract/array.rb', line 24 def initialize(element_contract) @contract = to_contract(element_contract) end |
Instance Method Details
#check!(other) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/flows/contract/array.rb', line 29 def check!(other) ARRAY_CONTRACT.check!(other) raise Error.new(other, report_errors(other)) unless other.all?(&@contract) true end |
#transform!(other) ⇒ Object
38 39 40 41 42 |
# File 'lib/flows/contract/array.rb', line 38 def transform!(other) check!(other) other.map { |elem| @contract.transform!(elem) } end |