module Trailblazer::Developer::Render::Linear

Constants

Operator

Public Instance Methods

call(operation, options = {style: :line}) click to toggle source
# File lib/trailblazer/developer/render/linear.rb, line 17
def call(operation, options = {style: :line})
  graph = Activity::Introspect::Graph(operation)

  rows = graph.collect do |node, i|
    next if node[:data][:stop_event] # DISCUSS: show this?

    created_by = node[:data][:dsl_track] || :pass

    [i, [created_by, node.id]]
  end.compact

  rows = rows[1..-1] # remove start

  return inspect_line(rows) if options[:style] == :line

  return inspect_rows(rows)
end
inspect_func(step) click to toggle source
# File lib/trailblazer/developer/render/linear.rb, line 35
def inspect_func(step)
  @inspect[step]
end
inspect_line(names) click to toggle source
# File lib/trailblazer/developer/render/linear.rb, line 41
def inspect_line(names)
  string = names.collect { |i, (end_of_edge, name)| "#{Operator[end_of_edge]}#{name}" }.join(",")
  "[#{string}]"
end
inspect_rows(names) click to toggle source
# File lib/trailblazer/developer/render/linear.rb, line 46
def inspect_rows(names)
  string = names.collect do |i, (end_of_edge, name)|
    operator = Operator[end_of_edge]

    op = "#{operator}#{name}"
    padding = 38

    proc = if operator == "<<"
             sprintf("%- #{padding}s", op)
           elsif [">", ">>", "&"].include?(operator.to_s)
             sprintf("% #{padding}s", op)
           else
             pad = " " * ((padding - op.length) / 2)
             "#{pad}#{op}#{pad}"
           end

    proc = proc.gsub(" ", "=")

    sprintf("%2d %s", i, proc)
  end.join("\n")
  "\n#{string}"
end