Class: Stannum::Contracts::TupleContract::Builder Private
- Inherits:
-
Stannum::Contract::Builder
- Object
- Base::Builder
- Stannum::Contract::Builder
- Stannum::Contracts::TupleContract::Builder
- Defined in:
- lib/stannum/contracts/tuple_contract.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Builder class for defining item constraints for a TupleContract.
This class should not be invoked directly. Instead, pass a block to the constructor for TupleContract.
Instance Method Summary collapse
-
#initialize(contract) ⇒ Builder
constructor
private
A new instance of Builder.
-
#item(constraint = nil, **options, &block) ⇒ Object
private
Defines an item constraint on the contract.
Methods inherited from Stannum::Contract::Builder
Constructor Details
#initialize(contract) ⇒ Builder
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.
Returns a new instance of Builder.
77 78 79 80 81 |
# File 'lib/stannum/contracts/tuple_contract.rb', line 77 def initialize(contract) super @current_index = -1 end |
Instance Method Details
#item(constraint, **options) ⇒ Object #item(**options) {|value| ... } ⇒ Object
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.
Defines an item constraint on the contract.
Each time an item constraint is defined, the constraint is tied to an incrementing index, i.e. the first constraint is matched against the item at index 0, the second at index 1, and so on. This can be overriden by setting the :property option.
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/stannum/contracts/tuple_contract.rb', line 102 def item(constraint = nil, **, &block) index = (@current_index += 1) self.constraint( constraint, property: index, property_type: :index, **, &block ) end |