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?)
-
#resolve ⇒ self
Resolve an instance of context.
- #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 44 |
# File 'lib/active_interactor/context/status.rb', line 39 def fail!(errors = nil) handle_errors(errors) if errors @_failed = true resolve raise ActiveInteractor::Error::ContextFailure, self end |
#failure? ⇒ Boolean Also known as: fail?
58 59 60 |
# File 'lib/active_interactor/context/status.rb', line 58 def failure? @_failed || false end |
#resolve ⇒ self
Resolve an instance of context. Called when an interactor is finished with it's context.
68 69 70 71 |
# File 'lib/active_interactor/context/status.rb', line 68 def resolve resolve_errors self 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.
81 82 83 84 85 86 |
# File 'lib/active_interactor/context/status.rb', line 81 def rollback! return false if @_rolled_back _called.reverse_each(&:rollback) @_rolled_back = true end |
#success? ⇒ Boolean Also known as: successful?
100 101 102 |
# File 'lib/active_interactor/context/status.rb', line 100 def success? !failure? end |