Class: ActionInteractor::Results
- Inherits:
-
Object
- Object
- ActionInteractor::Results
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/action_interactor/results.rb
Overview
Action Interactor Results
Provides a Hash
like object to Action Interactors execution results.
Instance Attribute Summary collapse
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
-
#add(attribute, result) ⇒ Object
Add
result
to the results hash. -
#delete(key) ⇒ Object
Delete a result for
key
. -
#each ⇒ Object
Iterates through each result key, value pair in the results hash.
-
#initialize ⇒ Results
constructor
A new instance of Results.
- #method_missing(attribute) ⇒ Object
Constructor Details
#initialize ⇒ Results
Returns a new instance of Results.
16 17 18 |
# File 'lib/action_interactor/results.rb', line 16 def initialize(*) @results = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(attribute) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/action_interactor/results.rb', line 38 def method_missing(attribute, *) # Define shortcut methods for each result key. # It returns the result for the key if results.has_key?(attribute) results[attribute] else super end end |
Instance Attribute Details
#results ⇒ Object (readonly)
Returns the value of attribute results.
12 13 14 |
# File 'lib/action_interactor/results.rb', line 12 def results @results end |
Instance Method Details
#add(attribute, result) ⇒ Object
Add result
to the results hash.
21 22 23 |
# File 'lib/action_interactor/results.rb', line 21 def add(attribute, result) results[attribute.to_sym] = result end |
#delete(key) ⇒ Object
Delete a result for key
.
26 27 28 29 |
# File 'lib/action_interactor/results.rb', line 26 def delete(key) attribute = key.to_sym results.delete(attribute) end |
#each ⇒ Object
Iterates through each result key, value pair in the results hash.
32 33 34 35 36 |
# File 'lib/action_interactor/results.rb', line 32 def each results.each_key do |attribute| yield attribute, results[attribute] end end |