class Funk::Instruments::GraphViz

Public Class Methods

new() click to toggle source
# File lib/funk/instruments/graph_viz.rb, line 4
def initialize
  @dots = []
end

Public Instance Methods

after_call(fn, input, value) click to toggle source
# File lib/funk/instruments/graph_viz.rb, line 8
def after_call(fn, input, value)
  name = "node #{fn.name}"
  style = {
    "label" => "< #{fn.name} <br/> #{value.inspect} >",
    "shape" => fn.is_a?(InputFn) ? "circle" : "box",
  }
  node = name + "[" + style.map { |attr,val| "#{attr}=#{val}" }.join(" ") + "]"

  @dots << node
  fn.dependencies.each do |dep|
    edge = "#{dep} -> #{fn.name}"
    @dots << edge
  end
end
digraph() click to toggle source
# File lib/funk/instruments/graph_viz.rb, line 23
def digraph
  digraph = []
  digraph << "digraph {"
  digraph.concat(@dots)
  digraph << "}"
  digraph.join("\n")
end