Class: Commande::Result
- Inherits:
- BasicObject
- Defined in:
- lib/commande.rb
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, successful?: true, failure?: true, fail!: true, prepare!: true, errors: true, error: true, logs: true, payload: true].freeze
Instance Method Summary collapse
- #add_error(*errors) ⇒ Object private
- #add_log(*logs) ⇒ Object private
-
#class ⇒ Object
Return the class for debugging purposes.
-
#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 = {}) ⇒ Commande::Result
constructor
private
Initialize a new result.
-
#inspect ⇒ String
Bare minimum inspect for debugging purposes.
-
#logs ⇒ Array
Returns all the logs collected during an operation.
-
#object_id ⇒ Fixnum
Alias for __id__.
- #payload ⇒ Object
-
#prepare!(payload) ⇒ Object
private
Prepare the result before to be returned.
-
#respond_to?(method_name, include_all = false) ⇒ TrueClass, FalseClass
Returns true if responds to the given method.
-
#successful? ⇒ TrueClass, FalseClass
Check if the current status is successful.
Constructor Details
#initialize(payload = {}) ⇒ Commande::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
29 30 31 32 33 34 |
# File 'lib/commande.rb', line 29 def initialize(payload = {}) @payload = payload @errors = [] @logs = [] @success = true end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ 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.
157 158 159 |
# File 'lib/commande.rb', line 157 def method_missing(method_name, *) @payload.fetch(method_name) { 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/commande.rb', line 68 def add_error(*errors) @errors << errors @errors.flatten! nil end |
#add_log(*logs) ⇒ 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.
98 99 100 101 102 |
# File 'lib/commande.rb', line 98 def add_log(*logs) @logs << logs @logs.flatten! nil end |
#class ⇒ Object
Return the class for debugging purposes.
121 122 123 |
# File 'lib/commande.rb', line 121 def class (class << self; self; end).superclass end |
#error ⇒ nil, String
Returns the first errors collected during an operation
83 84 85 |
# File 'lib/commande.rb', line 83 def error errors.first end |
#errors ⇒ Array
Returns all the errors collected during an operation
63 64 65 |
# File 'lib/commande.rb', line 63 def errors @errors.dup end |
#fail! ⇒ Object
Force the status to be a failure
51 52 53 |
# File 'lib/commande.rb', line 51 def fail! @success = false end |
#failure? ⇒ TrueClass, FalseClass
Check if the current status is not successful
46 47 48 |
# File 'lib/commande.rb', line 46 def failure? !successful? end |
#inspect ⇒ String
Bare minimum inspect for debugging purposes.
132 133 134 |
# File 'lib/commande.rb', line 132 def inspect "#<#{self.class}:#{::Kernel.format('0x0000%<id>x', id: (__id__ << 1))}#{__inspect}>" end |
#logs ⇒ Array
Returns all the logs collected during an operation
93 94 95 |
# File 'lib/commande.rb', line 93 def logs @logs.dup end |
#object_id ⇒ Fixnum
Alias for __id__
141 142 143 |
# File 'lib/commande.rb', line 141 def object_id __id__ end |
#payload ⇒ Object
114 115 116 |
# File 'lib/commande.rb', line 114 def payload @payload.dup 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
109 110 111 112 |
# File 'lib/commande.rb', line 109 def prepare!(payload) @payload.merge!(payload) self end |
#respond_to?(method_name, include_all = false) ⇒ TrueClass, FalseClass
Returns true if responds to the given method.
150 151 152 |
# File 'lib/commande.rb', line 150 def respond_to?(method_name, include_all = false) respond_to_missing?(method_name, include_all) end |
#successful? ⇒ TrueClass, FalseClass
Check if the current status is successful
39 40 41 |
# File 'lib/commande.rb', line 39 def successful? @success && errors.empty? end |