Class: Roast::Workflow::OutputManager

Inherits:
Object
  • Object
show all
Defined in:
lib/roast/workflow/output_manager.rb

Overview

Manages workflow output, including both the key-value output hash and the final output string/array

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOutputManager

Returns a new instance of OutputManager.



8
9
10
11
12
# File 'lib/roast/workflow/output_manager.rb', line 8

def initialize
  @output = ActiveSupport::HashWithIndifferentAccess.new
  @output_wrapper = nil
  @final_output = []
end

Instance Attribute Details

#final_outputObject

Get the final output as a string



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/roast/workflow/output_manager.rb', line 36

def final_output
  return @final_output if @final_output.is_a?(String)
  return "" if @final_output.nil?

  # Handle array case (expected normal case)
  if @final_output.respond_to?(:join)
    @final_output.join("\n\n")
  else
    # Handle any other unexpected type by converting to string
    @final_output.to_s
  end
end

Instance Method Details

#append_to_final_output(message) ⇒ Object

Append a message to the final output



31
32
33
# File 'lib/roast/workflow/output_manager.rb', line 31

def append_to_final_output(message)
  @final_output << message
end

#from_h(data) ⇒ Object

Restore state from a hash



66
67
68
69
70
71
# File 'lib/roast/workflow/output_manager.rb', line 66

def from_h(data)
  return unless data

  self.output = data[:output] if data.key?(:output)
  self.final_output = data[:final_output] if data.key?(:final_output)
end

#outputObject

Get output wrapped in DotAccessHash for dot notation access



15
16
17
# File 'lib/roast/workflow/output_manager.rb', line 15

def output
  @output_wrapper ||= DotAccessHash.new(@output)
end

#output=(value) ⇒ Object

Set output, ensuring it’s always a HashWithIndifferentAccess



20
21
22
23
24
25
26
27
28
# File 'lib/roast/workflow/output_manager.rb', line 20

def output=(value)
  @output = if value.is_a?(ActiveSupport::HashWithIndifferentAccess)
    value
  else
    ActiveSupport::HashWithIndifferentAccess.new(value)
  end
  # Reset the wrapper when output changes
  @output_wrapper = nil
end

#raw_outputObject

Get the raw output hash (for internal use)



53
54
55
# File 'lib/roast/workflow/output_manager.rb', line 53

def raw_output
  @output
end

#to_hObject

Get a snapshot of the current state for persistence



58
59
60
61
62
63
# File 'lib/roast/workflow/output_manager.rb', line 58

def to_h
  {
    output: @output.to_h,
    final_output: @final_output,
  }
end