Module: Trailblazer::Activity::Introspect::Render

Defined in:
lib/trailblazer/activity/introspect/render.rb

Class Method Summary collapse

Class Method Details

.call(activity, **options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/trailblazer/activity/introspect/render.rb', line 8

def call(activity, **options)
  nodes       = Introspect.Nodes(activity)
  circuit_map = activity.to_h[:circuit].to_h[:map]

  content = nodes.collect do |task, node|
    outgoings = circuit_map[task]

    conns = outgoings.collect do |signal, target|
      " {#{signal}} => #{inspect_with_matcher(target, **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) ⇒ Object



40
41
42
43
44
45
# File 'lib/trailblazer/activity/introspect/render.rb', line 40

def inspect_end(task)
  class_name = strip(task.class)
  options    = task.to_h

  "#<#{class_name}/#{options[:semantic].inspect}>"
end

.inspect_task(task) ⇒ Object



36
37
38
# File 'lib/trailblazer/activity/introspect/render.rb', line 36

def inspect_task(task)
  task.inspect
end

.inspect_with_matcher(task, inspect_task: method(:inspect_task), inspect_end: method(:inspect_end)) ⇒ Object

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



31
32
33
34
# File 'lib/trailblazer/activity/introspect/render.rb', line 31

def inspect_with_matcher(task, inspect_task: method(:inspect_task), inspect_end: method(:inspect_end))
  return inspect_task.(task) unless task.is_a?(Trailblazer::Activity::End)
  inspect_end.(task)
end

.strip(string) ⇒ Object



47
48
49
# File 'lib/trailblazer/activity/introspect/render.rb', line 47

def strip(string)
  string.to_s.sub("Trailblazer::Activity::", "")
end