Class: Fractor::WorkResult

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#errorObject (readonly)

Returns the value of attribute error.



7
8
9
# File 'lib/fractor/work_result.rb', line 7

def error
  @error
end

#resultObject (readonly)

Returns the value of attribute result.



7
8
9
# File 'lib/fractor/work_result.rb', line 7

def result
  @result
end

#workObject (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

#inspectObject



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

Returns:

  • (Boolean)


15
16
17
# File 'lib/fractor/work_result.rb', line 15

def success?
  !@error
end

#to_sObject



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