module Trailblazer::Developer::Render::Circuit

Public Class Methods

strip(string) click to toggle source
# File lib/trailblazer/developer/render/circuit.rb, line 51
def self.strip(string)
  string.to_s.sub("Trailblazer::Activity::", "")
end

Public Instance Methods

call(activity, **options) click to toggle source

Render an {Activity}'s circuit as a simple hash.

# File lib/trailblazer/developer/render/circuit.rb, line 14
def call(activity, **options)
  graph = Activity::Introspect::Graph(activity)

  circuit_hash(graph, **options)
end
circuit_hash(graph, **options) click to toggle source
# File lib/trailblazer/developer/render/circuit.rb, line 20
def circuit_hash(graph, **options)
  content = graph.collect do |node|
    conns = node.outgoings.collect do |outgoing|
      " {#{outgoing.output.signal}} => #{inspect_with_matcher(outgoing.task, **options)}"
    end

    [ inspect_with_matcher(node.task, **options), conns.join("\n") ]
  end

  content = content.join("\n")

  "\n#{content}".gsub(/0x\w+/, "0x")
end
inspect_end(task) click to toggle source
# File lib/trailblazer/developer/render/circuit.rb, line 44
def inspect_end(task)
  class_name = Render::Circuit.strip(task.class)
  options    = task.to_h

  "#<#{class_name}/#{options[:semantic].inspect}>"
end
inspect_task(task) click to toggle source
# File lib/trailblazer/developer/render/circuit.rb, line 40
def inspect_task(task)
  task.inspect
end
inspect_with_matcher(task, inspect_task: method(:inspect_task), inspect_end: method(:inspect_end)) click to toggle source

If Ruby had pattern matching, this function wasn't necessary.

# File lib/trailblazer/developer/render/circuit.rb, line 35
def inspect_with_matcher(task, inspect_task: method(:inspect_task), inspect_end: method(:inspect_end))
  return inspect_task.(task) unless task.kind_of?(Trailblazer::Activity::End)
  inspect_end.(task)
end