Class: Funk::Instruments::GraphViz

Inherits:
Object
  • Object
show all
Defined in:
lib/funk/instruments/graph_viz.rb

Instance Method Summary collapse

Constructor Details

#initializeGraphViz

Returns a new instance of GraphViz.



4
5
6
# File 'lib/funk/instruments/graph_viz.rb', line 4

def initialize
  @dots = []
end

Instance Method Details

#after_call(fn, input, value) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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

#digraphObject



23
24
25
26
27
28
29
# File 'lib/funk/instruments/graph_viz.rb', line 23

def digraph
  digraph = []
  digraph << "digraph {"
  digraph.concat(@dots)
  digraph << "}"
  digraph.join("\n")
end