Module: Trailblazer::Developer::Render::Circuit
- Defined in:
- lib/trailblazer/developer/render/circuit.rb
Class Method Summary collapse
-
.call(activity, **options) ⇒ Object
Render an Activity‘s circuit as a simple hash.
- .circuit_hash(graph, **options) ⇒ Object
- .inspect_end(task) ⇒ Object
- .inspect_task(task) ⇒ Object
-
.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.
- .strip(string) ⇒ Object
Class Method Details
.call(activity, **options) ⇒ Object
Render an Activity‘s circuit as a simple hash.
14 15 16 17 18 |
# File 'lib/trailblazer/developer/render/circuit.rb', line 14 def call(activity, **) graph = Activity::Introspect::Graph(activity) circuit_hash(graph, **) end |
.circuit_hash(graph, **options) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/trailblazer/developer/render/circuit.rb', line 20 def circuit_hash(graph, **) content = graph.collect do |node| conns = node.outgoings.collect do |outgoing| " {#{outgoing.output.signal}} => #{inspect_with_matcher(outgoing.task, **)}" end [ inspect_with_matcher(node.task, **), conns.join("\n") ] end content = content.join("\n") "\n#{content}".gsub(/0x\w+/, "0x") end |
.inspect_end(task) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/trailblazer/developer/render/circuit.rb', line 44 def inspect_end(task) class_name = Render::Circuit.strip(task.class) = task.to_h "#<#{class_name}/#{[:semantic].inspect}>" end |
.inspect_task(task) ⇒ Object
40 41 42 |
# 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)) ⇒ Object
If Ruby had pattern matching, this function wasn’t necessary.
35 36 37 38 |
# 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 |
.strip(string) ⇒ Object
51 52 53 |
# File 'lib/trailblazer/developer/render/circuit.rb', line 51 def self.strip(string) string.to_s.sub("Trailblazer::Activity::", "") end |