Class: Stannum::Contracts::ParametersContract::Builder Private
- Inherits:
-
Stannum::Contract::Builder
- Object
- Base::Builder
- Stannum::Contract::Builder
- Stannum::Contracts::ParametersContract::Builder
- Defined in:
- lib/stannum/contracts/parameters_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 ParametersContract.
This class should not be invoked directly. Instead, pass a block to the constructor for ParametersContract.
Instance Method Summary collapse
-
#argument(name, type = nil, index: nil, **options, &block) ⇒ Object
private
Adds an argument constraint to the contract.
-
#arguments(name, type) ⇒ Stannum::Contracts::ParametersContract::Builder
private
Sets the variadic arguments constraint for the contract.
-
#block(present) ⇒ Stannum::Contracts::ParametersContract
private
Sets the block parameter constraint for the contract.
-
#keyword(name, type = nil, **options, &block) ⇒ Object
private
Adds a keyword constraint to the contract.
-
#keywords(name, type) ⇒ Stannum::Contracts::ParametersContract::Builder
private
Sets the variadic keywords constraint for the contract.
Methods inherited from Stannum::Contract::Builder
Instance Method Details
#argument(name, type, index: nil, **options) ⇒ Stannum::Contracts::ParametersContract::Builder #argument(name, index: nil, **options) {|actual| ... } ⇒ Stannum::Contracts::ParametersContract::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.
Adds an argument constraint to the contract.
If the index is specified, then the constraint will be added for the argument at the specified index. If the index is not given, then the constraint will be applied to the next unconstrained argument. For example, the first argument constraint will be added for the argument at index 0, the second constraint for the argument at index 1, and so on.
233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/stannum/contracts/parameters_contract.rb', line 233 def argument(name, type = nil, index: nil, **, &block) type = resolve_constraint_or_type(type, **, &block) contract.add_argument_constraint( index, type, property_name: name, ** ) self end |
#arguments(name, type) ⇒ Stannum::Contracts::ParametersContract::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.
Sets the variadic arguments constraint for the contract.
If the parameters includes variadic (or “splatted”) arguments, then each item in the variadic arguments array must match the given type or constraint. If the type is a constraint, then the given constraint will be copied with the given options. If the type is a Class or a Module, then a Stannum::Constraints::Type constraint will be created with the given type.
264 265 266 267 268 |
# File 'lib/stannum/contracts/parameters_contract.rb', line 264 def arguments(name, type) contract.set_arguments_item_constraint(name, type) self end |
#block(present) ⇒ Stannum::Contracts::ParametersContract
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.
Sets the block parameter constraint for the contract.
If the expected presence is true, a block must be given as part of the parameters. If the expected presence is false, a block must not be given. If the presence is a constraint, then the block must match the constraint.
284 285 286 287 288 |
# File 'lib/stannum/contracts/parameters_contract.rb', line 284 def block(present) contract.set_block_constraint(present) self end |
#keyword(name, type, **options) ⇒ Stannum::Contracts::ParametersContract::Builder #keyword(name, **options) {|actual| ... } ⇒ Stannum::Contracts::ParametersContract::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.
Adds a keyword constraint to the contract.
323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/stannum/contracts/parameters_contract.rb', line 323 def keyword(name, type = nil, **, &block) type = resolve_constraint_or_type(type, **, &block) contract.add_keyword_constraint( name, type, ** ) self end |
#keywords(name, type) ⇒ Stannum::Contracts::ParametersContract::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.
Sets the variadic keywords constraint for the contract.
If the parameters includes variadic (or “splatted”) keywords, then each value in the variadic keywords hash must match the given type or constraint. If the type is a constraint, then the given constraint will be copied with the given options. If the type is a Class or a Module, then a Stannum::Constraints::Type constraint will be created with the given type.
353 354 355 356 357 |
# File 'lib/stannum/contracts/parameters_contract.rb', line 353 def keywords(name, type) contract.set_keywords_value_constraint(name, type) self end |