class KnifeDraw::ChefGraph

Constants

EDGE_COLOR
FONT_NAME
NODE_COLOR
ROLE_COLOR
RUNLIST_COLOR

Attributes

graph[R]

Public Class Methods

new(cluster_environments: false) click to toggle source
# File lib/knife_draw/chef_graph.rb, line 13
def initialize(cluster_environments: false)
  @graph =  GraphViz.new(:KnifeDraw, rankdir: :LR, strict: true, fontname: FONT_NAME)
  @cluster_environments = cluster_environments
end

Public Instance Methods

connect(source, target) click to toggle source
# File lib/knife_draw/chef_graph.rb, line 40
def connect(source, target)
  graph.add_edge(source, target, color: EDGE_COLOR)
end
draw!(outputfile) click to toggle source
# File lib/knife_draw/chef_graph.rb, line 44
def draw!(outputfile)
  filename=outputfile
  format = File.extname(filename)[1..-1] || :png
  graph.output format => filename
end
draw_node(name, environment) click to toggle source
# File lib/knife_draw/chef_graph.rb, line 28
def draw_node(name, environment)
  environments[environment.to_s].add_nodes(name, shape: :box3d, fillcolor: NODE_COLOR, style: :filled, fontname: FONT_NAME)
end
draw_role(name) click to toggle source
# File lib/knife_draw/chef_graph.rb, line 32
def draw_role(name)
  graph.add_nodes(name, shape: :component, fillcolor: ROLE_COLOR, style: :filled, fontname: FONT_NAME)
end
draw_runlist(name) click to toggle source
# File lib/knife_draw/chef_graph.rb, line 36
def draw_runlist(name)
  graph.add_nodes(name, shape: :note, fillcolor: RUNLIST_COLOR, style: :filled, fontname: FONT_NAME)
end
env_prefix() click to toggle source
# File lib/knife_draw/chef_graph.rb, line 18
def env_prefix
  @cluster_environments ? "cluster" : "env_"
end
environments() click to toggle source
# File lib/knife_draw/chef_graph.rb, line 22
def environments
  @environments ||= Hash.new {|hash, key|
    hash[key] = graph.add_graph("#{env_prefix}#{key}", label: key, fontname: FONT_NAME)
  }
end