Class: Hanami::Interactor::Result
- Inherits:
- Utils::BasicObject
- Defined in:
- lib/hanami/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
::Hash[initialize: true, success?: true, successful?: true, failure?: 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.
-
#failure? ⇒ TrueClass, FalseClass
Check if the current status is not successful.
-
#initialize(payload = {}) ⇒ Hanami::Interactor::Result
constructor
private
Initialize a new result.
-
#prepare!(payload) ⇒ Object
private
Prepare the result before to be returned.
-
#successful? ⇒ TrueClass, FalseClass
(also: #success?)
Check if the current status is successful.
Methods inherited from Utils::BasicObject
#class, #inspect, #object_id, #pretty_print, #respond_to?
Constructor Details
#initialize(payload = {}) ⇒ Hanami::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
37 38 39 40 41 |
# File 'lib/hanami/interactor.rb', line 37 def initialize(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.
122 123 124 |
# File 'lib/hanami/interactor.rb', line 122 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.
87 88 89 90 91 |
# File 'lib/hanami/interactor.rb', line 87 def add_error(*errors) @errors << errors @errors.flatten! nil end |
#error ⇒ nil, String
Returns the first errors collected during an operation
103 104 105 |
# File 'lib/hanami/interactor.rb', line 103 def error errors.first end |
#errors ⇒ Array
Returns all the errors collected during an operation
81 82 83 |
# File 'lib/hanami/interactor.rb', line 81 def errors @errors.dup end |
#fail! ⇒ Object
Force the status to be a failure
67 68 69 |
# File 'lib/hanami/interactor.rb', line 67 def fail! @success = false end |
#failure? ⇒ TrueClass, FalseClass
Check if the current status is not successful
60 61 62 |
# File 'lib/hanami/interactor.rb', line 60 def failure? !successful? 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
113 114 115 116 |
# File 'lib/hanami/interactor.rb', line 113 def prepare!(payload) @payload.merge!(payload) self end |
#successful? ⇒ TrueClass, FalseClass Also known as: success?
Check if the current status is successful
48 49 50 |
# File 'lib/hanami/interactor.rb', line 48 def successful? @success && errors.empty? end |