Module: Rake::Tree

Defined in:
lib/rake/tree.rb,
lib/rake/tree/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.produce_graphvizObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/rake/tree.rb', line 15

def produce_graphviz
  Rake.application.load_rakefile
  puts 'digraph rake {'
  Rake::Task.tasks.each do |task|
    task.prerequisites.each do |pre|
      puts %Q(  "#{task.name}" -> "#{pre}")
    end
  end
  puts '}'
end

.write_viz(output_file) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rake/tree.rb', line 26

def write_viz(output_file)
  graphviz_io = StringIO.new
  old_stdout = $stdout
  $stdout = graphviz_io
  begin
    produce_graphviz
  ensure
    $stdout = old_stdout
  end
  graphviz_text = graphviz_io.string

  case File.extname(output_file)
  when '.dot'
    File.write(output_file, graphviz_text)
  when '.png'
    with_temp_dot graphviz_text do |filename|
      `dot -Tpng #{filename} -o #{output_file}`
    end
  when '.svg'
    with_temp_dot graphviz_text do |filename|
      `dot -Tsvg #{filename} -o #{output_file}`
    end
  end
end