Class: Stannum::Contracts::Builder
- Inherits:
-
Object
- Object
- Stannum::Contracts::Builder
- Defined in:
- lib/stannum/contracts/builder.rb
Overview
Abstract base class for contract builder classes.
A contract builder provides a Domain-Specific Language for defining constraints on a contract. They are typically used during initialization if a block is passed to Contract#new.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#contract ⇒ Stannum::Contract
readonly
The contract to which constraints are added.
Instance Method Summary collapse
-
#concat(other) ⇒ self
Concatenate the constraints from the given other contract.
-
#constraint(constraint = nil, **options, &block) ⇒ Object
Adds a constraint to the contract.
-
#initialize(contract) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(contract) ⇒ Builder
Returns a new instance of Builder.
14 15 16 |
# File 'lib/stannum/contracts/builder.rb', line 14 def initialize(contract) @contract = contract end |
Instance Attribute Details
#contract ⇒ Stannum::Contract (readonly)
Returns The contract to which constraints are added.
19 20 21 |
# File 'lib/stannum/contracts/builder.rb', line 19 def contract @contract end |
Instance Method Details
#concat(other) ⇒ self
Concatenate the constraints from the given other contract.
28 29 30 |
# File 'lib/stannum/contracts/builder.rb', line 28 def concat(other) contract.concat(other) end |
#constraint(constraint, **options) ⇒ Object #constraint(**options, &block) ⇒ Object
Adds a constraint to the contract.
50 51 52 53 54 55 56 |
# File 'lib/stannum/contracts/builder.rb', line 50 def constraint(constraint = nil, **, &block) constraint = resolve_constraint(constraint, **, &block) contract.add_constraint(constraint, **) self end |