Module: Interactor::Contracts::DSL
- Defined in:
- lib/interactor/contracts/dsl.rb
Overview
Defines the class-level DSL that enables Interactor contracts.
Instance Method Summary collapse
-
#config(&block) ⇒ void
Sends configuration set up to the underlying contracts in the terms.
-
#contract ⇒ Contract
The Contract to enforce on calls to the Interactor.
-
#expects(&block) ⇒ void
Defines the expectations of an Interactor and creates a before hook.
-
#inherit_contract(contract) ⇒ void
private
Allows for the inheritance of contracts in subclasses.
-
#on_breach(&block) ⇒ void
Defines a consequence that is called when a contract is breached.
-
#promises(&block) ⇒ void
(also: #assures)
Defines the promises of an Interactor and creates an after hook.
Instance Method Details
#config(&block) ⇒ void
This method returns an undefined value.
Sends configuration set up to the underlying contracts in the terms
51 52 53 |
# File 'lib/interactor/contracts/dsl.rb', line 51 def config(&block) contract.config(&block) end |
#contract ⇒ Contract
The Contract to enforce on calls to the Interactor
71 72 73 |
# File 'lib/interactor/contracts/dsl.rb', line 71 def contract @contract ||= Contract.new end |
#expects(&block) ⇒ void
This method returns an undefined value.
Defines the expectations of an Interactor and creates a before hook
97 98 99 100 |
# File 'lib/interactor/contracts/dsl.rb', line 97 def expects(&block) contract.add_expectation(&block) define_expectations_hook end |
#inherit_contract(contract) ⇒ 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.
Allows for the inheritance of contracts in subclasses
107 108 109 110 111 112 113 114 115 |
# File 'lib/interactor/contracts/dsl.rb', line 107 def inherit_contract(contract) @contract = Contract.new( promises: contract.promises.clone, expectations: contract.expectations.clone, consequences: contract.consequences.clone ) define_promises_hook define_expectations_hook end |
#on_breach(&block) ⇒ void
This method returns an undefined value.
Defines a consequence that is called when a contract is breached
142 143 144 |
# File 'lib/interactor/contracts/dsl.rb', line 142 def on_breach(&block) contract.add_consequence(block) end |
#promises(&block) ⇒ void Also known as: assures
This method returns an undefined value.
Defines the promises of an Interactor and creates an after hook
28 29 30 31 |
# File 'lib/interactor/contracts/dsl.rb', line 28 def promises(&block) contract.add_promise(&block) define_promises_hook end |