Module: ActiveInteractor::Context::Status
- Included in:
- Base
- Defined in:
- lib/active_interactor/context/status.rb
Overview
Instance Method Summary collapse
-
#called!(interactor) ⇒ Array<Class>
Add an instance of interactor to the list of interactors called on the context.
-
#fail!(errors = nil) ⇒ Object
Fail the context instance.
- #failure? ⇒ Boolean (also: #fail?)
- #rollback! ⇒ Boolean
-
#success? ⇒ Boolean
(also: #successful?)
Whether the context instance is successful.
Instance Method Details
#called!(interactor) ⇒ Array<Class>
Add an instance of interactor to the list of interactors called on the context. This list is used when #rollback! is called on a context instance.
17 18 19 |
# File 'lib/active_interactor/context/status.rb', line 17 def called!(interactor) _called << interactor end |
#fail!(errors = nil) ⇒ Object
Fail the context instance. Failing an instance raises an error that may be rescued by the calling interactor. The instance is also flagged as having failed.
39 40 41 42 43 |
# File 'lib/active_interactor/context/status.rb', line 39 def fail!(errors = nil) merge_errors!(errors) if errors @_failed = true raise ActiveInteractor::Error::ContextFailure, self end |
#failure? ⇒ Boolean Also known as: fail?
57 58 59 |
# File 'lib/active_interactor/context/status.rb', line 57 def failure? @_failed || false end |
#rollback! ⇒ Boolean
Rollback an instance of context. Any interactors the instance has been passed via the #called! method are asked to roll themselves back by invoking their #rollback methods. The instance is also flagged as rolled back.
70 71 72 73 74 75 |
# File 'lib/active_interactor/context/status.rb', line 70 def rollback! return false if @_rolled_back _called.reverse_each(&:rollback) @_rolled_back = true end |
#success? ⇒ Boolean Also known as: successful?
89 90 91 |
# File 'lib/active_interactor/context/status.rb', line 89 def success? !failure? end |