Class: SpotFlow::ExecutionPrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/spot_flow/execution.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(execution) ⇒ ExecutionPrinter

Returns a new instance of ExecutionPrinter.



326
327
328
# File 'lib/spot_flow/execution.rb', line 326

def initialize(execution)
  @execution = execution
end

Instance Attribute Details

#executionObject

Returns the value of attribute execution.



324
325
326
# File 'lib/spot_flow/execution.rb', line 324

def execution
  @execution
end

Instance Method Details



330
331
332
333
334
335
336
# File 'lib/spot_flow/execution.rb', line 330

def print
  puts
  puts "#{execution.step.id} #{execution.status} * #{execution.tokens.join(', ')}"
  print_variables unless execution.variables.empty?
  print_children
  puts
end


345
346
347
348
349
350
351
352
353
# File 'lib/spot_flow/execution.rb', line 345

def print_child(child, index)
  str = "#{index} #{child.step.class.name.demodulize} #{child.step.id}: #{child.status} #{JSON.pretty_generate(child.variables, { indent: '', object_nl: ' ' }) unless child.variables.empty? }".strip
  str = "#{str} * in: #{child.tokens_in.join(', ')}" if child.tokens_in.present?
  str = "#{str} * out: #{child.tokens_out.join(', ')}" if child.tokens_out.present?
  puts str
  child.children.each_with_index do |grandchild, grandindex|
    print_child(grandchild, "#{index}.#{grandindex}")
  end
end


338
339
340
341
342
343
# File 'lib/spot_flow/execution.rb', line 338

def print_children
  puts
  execution.children.each_with_index do |child, index|
    print_child(child, index)
  end
end


355
356
357
358
# File 'lib/spot_flow/execution.rb', line 355

def print_variables
  puts
  puts JSON.pretty_generate(execution.variables)
end