class Pipely::GraphBuilder

Builds a GraphViz graph from a set of Components and their Dependencies

Public Class Methods

new(graph=nil) click to toggle source
# File lib/pipely/graph_builder.rb, line 9
def initialize(graph=nil)
  @graph = graph || GraphViz.new(:G, :type => :digraph)
end

Public Instance Methods

build(components) click to toggle source
# File lib/pipely/graph_builder.rb, line 13
def build(components)
  add_nodes(components)
  add_edges(components)
  @graph
end

Private Instance Methods

add_edge(component, dependency) click to toggle source
# File lib/pipely/graph_builder.rb, line 37
def add_edge(component, dependency)
  options = {
    :label => dependency.label,
    :color => dependency.color,
  }

  options[:dir] = 'back' if ('input' == dependency.label)

  if 'output' == dependency.label
    @graph.add_edges(
      dependency.target_id,
      component.id,
      options
    )
  else
    @graph.add_edges(
      component.id,
      dependency.target_id,
      options
    )
  end
end
add_edges(components) click to toggle source

Represent Dependencies as edges on the graph

# File lib/pipely/graph_builder.rb, line 29
def add_edges(components)
  components.each do |component|
    component.dependencies.each do |dependency|
      add_edge(component, dependency)
    end
  end
end
add_nodes(components) click to toggle source

Represent Components as nodes on the graph

# File lib/pipely/graph_builder.rb, line 22
def add_nodes(components)
  components.each do |component|
    @graph.add_nodes(component.id, component.graphviz_options)
  end
end