Class: Lotus::Interactor::Result
- Inherits:
- Utils::BasicObject
- Defined in:
- lib/lotus/interactor.rb
Overview
Result of an operation
Constant Summary collapse
- METHODS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Concrete methods
{initialize: true, success?: true, fail!: true, prepare!: true, errors: true, error: true}.freeze
Instance Method Summary collapse
- #add_error(*errors) ⇒ Object private
-
#error ⇒ nil, String
Returns the first errors collected during an operation.
-
#errors ⇒ Array
Returns all the errors collected during an operation.
-
#fail! ⇒ Object
Force the status to be a failure.
-
#initialize(payload = {}) ⇒ Lotus::Interactor::Result
constructor
private
Initialize a new result.
-
#prepare!(payload) ⇒ Object
private
Prepare the result before to be returned.
-
#success? ⇒ TrueClass, FalseClass
Check if the current status is successful.
Methods inherited from Utils::BasicObject
#class, #inspect, #respond_to?
Constructor Details
#initialize(payload = {}) ⇒ Lotus::Interactor::Result
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.
Initialize a new result
30 31 32 33 34 |
# File 'lib/lotus/interactor.rb', line 30 def initialize(payload = {}) @payload = _payload(payload) @errors = [] @success = true end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m) ⇒ Object (protected)
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.
102 103 104 |
# File 'lib/lotus/interactor.rb', line 102 def method_missing(m, *) @payload.fetch(m) { super } end |
Instance Method Details
#add_error(*errors) ⇒ Object
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.
68 69 70 71 72 |
# File 'lib/lotus/interactor.rb', line 68 def add_error(*errors) @errors << errors @errors.flatten! nil end |
#error ⇒ nil, String
Returns the first errors collected during an operation
84 85 86 |
# File 'lib/lotus/interactor.rb', line 84 def error errors.first end |
#errors ⇒ Array
Returns all the errors collected during an operation
62 63 64 |
# File 'lib/lotus/interactor.rb', line 62 def errors @errors.dup end |
#fail! ⇒ Object
Force the status to be a failure
48 49 50 |
# File 'lib/lotus/interactor.rb', line 48 def fail! @success = false end |
#prepare!(payload) ⇒ Object
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.
Prepare the result before to be returned
94 95 96 97 |
# File 'lib/lotus/interactor.rb', line 94 def prepare!(payload) @payload.merge!(_payload(payload)) self end |
#success? ⇒ TrueClass, FalseClass
Check if the current status is successful
41 42 43 |
# File 'lib/lotus/interactor.rb', line 41 def success? @success && errors.empty? end |