Method: Puppet::Graph::SimpleGraph#write_cycles_to_graph

Defined in:
lib/puppet/graph/simple_graph.rb

#write_cycles_to_graph(cycles) ⇒ Object



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/puppet/graph/simple_graph.rb', line 251

def write_cycles_to_graph(cycles)
  # This does not use the DOT graph library, just writes the content
  # directly.  Given the complexity of this, there didn't seem much point
  # using a heavy library to generate exactly the same content. --daniel 2011-01-27
  graph = ["digraph Resource_Cycles {"]
  graph << '  label = "Resource Cycles"'

  cycles.each do |cycle|
    paths_in_cycle(cycle, 10).each do |path|
      graph << path.map { |v| '"' + v.to_s.gsub(/"/, '\\"') + '"' }.join(" -> ")
    end
  end

  graph << '}'

  filename = File.join(Puppet[:graphdir], "cycles.dot")
  # DOT files are assumed to be UTF-8 by default - http://www.graphviz.org/doc/info/lang.html
  File.open(filename, "w:UTF-8") { |f| f.puts graph }
  filename
end