Class: Interactor::Contracts::Contract
- Inherits:
-
Object
- Object
- Interactor::Contracts::Contract
- Defined in:
- lib/interactor/contracts/contract.rb
Overview
Contains the promises, expectations, and consequences of an interactor’s contract.
Instance Attribute Summary collapse
-
#expectations ⇒ Terms
readonly
The expectations for arguments passed into the Interactor.
-
#promises ⇒ Terms
readonly
The promises the Contract will fulfill.
Instance Method Summary collapse
-
#add_consequence(consequence) ⇒ void
Adds a consequence to the Contract’s set of consequences.
-
#add_expectation(&term) ⇒ void
Adds an expectation to the Contract’s set of expectations.
-
#add_promise(&term) ⇒ void
Adds an promise to the Contract’s set of promises.
-
#config(&block) ⇒ void
private
Configures the underlying contracts for the validation schemata.
-
#consequences ⇒ Array<#call>
The consequences for the Contract.
-
#initialize(promises: Terms.new, expectations: Terms.new, consequences: []) ⇒ Contract
constructor
Instantiates a new Contract with the given constraints.
Constructor Details
#initialize(promises: Terms.new, expectations: Terms.new, consequences: []) ⇒ Contract
Instantiates a new Contract with the given constraints
rubocop:disable Metrics/LineLength
20 21 22 23 24 |
# File 'lib/interactor/contracts/contract.rb', line 20 def initialize(promises: Terms.new, expectations: Terms.new, consequences: []) @promises = promises @consequences = consequences @expectations = expectations end |
Instance Attribute Details
#expectations ⇒ Terms (readonly)
The expectations for arguments passed into the Interactor
45 46 47 |
# File 'lib/interactor/contracts/contract.rb', line 45 def expectations @expectations end |
#promises ⇒ Terms (readonly)
The promises the Contract will fulfill
35 36 37 |
# File 'lib/interactor/contracts/contract.rb', line 35 def promises @promises end |
Instance Method Details
#add_consequence(consequence) ⇒ void
This method returns an undefined value.
Adds a consequence to the Contract’s set of consequences
73 74 75 |
# File 'lib/interactor/contracts/contract.rb', line 73 def add_consequence(consequence) @consequences << consequence end |
#add_expectation(&term) ⇒ void
This method returns an undefined value.
Adds an expectation to the Contract’s set of expectations
88 89 90 |
# File 'lib/interactor/contracts/contract.rb', line 88 def add_expectation(&term) expectations.add(&term) end |
#add_promise(&term) ⇒ void
This method returns an undefined value.
Adds an promise to the Contract’s set of promises
58 59 60 |
# File 'lib/interactor/contracts/contract.rb', line 58 def add_promise(&term) promises.add(&term) end |
#config(&block) ⇒ void
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.
This method returns an undefined value.
Configures the underlying contracts for the validation schemata
97 98 99 100 |
# File 'lib/interactor/contracts/contract.rb', line 97 def config(&block) promises.config(&block) expectations.config(&block) end |
#consequences ⇒ Array<#call>
The consequences for the Contract
110 111 112 113 114 115 116 |
# File 'lib/interactor/contracts/contract.rb', line 110 def consequences if @consequences.empty? Array(default_consequence) else @consequences end end |