Class: Fractor::WorkResult
- Inherits:
-
Object
- Object
- Fractor::WorkResult
- Defined in:
- lib/fractor/work_result.rb
Overview
Represents the result of processing a Work item. Can hold either a successful result or an error.
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#work ⇒ Object
readonly
Returns the value of attribute work.
Instance Method Summary collapse
-
#initialize(result: nil, error: nil, work: nil) ⇒ WorkResult
constructor
A new instance of WorkResult.
- #inspect ⇒ Object
- #success? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(result: nil, error: nil, work: nil) ⇒ WorkResult
Returns a new instance of WorkResult.
9 10 11 12 13 |
# File 'lib/fractor/work_result.rb', line 9 def initialize(result: nil, error: nil, work: nil) @result = result @error = error @work = work end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
7 8 9 |
# File 'lib/fractor/work_result.rb', line 7 def error @error end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
7 8 9 |
# File 'lib/fractor/work_result.rb', line 7 def result @result end |
#work ⇒ Object (readonly)
Returns the value of attribute work.
7 8 9 |
# File 'lib/fractor/work_result.rb', line 7 def work @work end |
Instance Method Details
#inspect ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/fractor/work_result.rb', line 27 def inspect { result: @result, error: @error, work: @work&.to_s, # Use safe navigation for work } end |
#success? ⇒ Boolean
15 16 17 |
# File 'lib/fractor/work_result.rb', line 15 def success? !@error end |
#to_s ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/fractor/work_result.rb', line 19 def to_s if success? "Result: #{@result}" else "Error: #{@error}, Work: #{@work}" end end |