Class: Depcheck::GraphOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/depcheck/output/graph_output.rb

Instance Method Summary collapse

Instance Method Details

#post(objs, include, dot) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/depcheck/output/graph_output.rb', line 4

def post(objs, include, dot)

  # installs graphviz if needed
  system 'brew install graphviz' unless graphviz_installed?

  # Check that this is in the user's PATH after installing
  unless graphviz_installed?
    fail "graphviz is not in the user's PATH, or it failed to install"
  end

  # generate graph description
  graph = generate_graph_description(objs, include)

  # create temporary graph dot file
  file_name = 'graph'
  File.open("#{file_name}.dot", 'w') do |f|
    f.write(graph)
  end

  # run dot command
  if dot
  `dot -T png #{file_name}.dot`
  elsif
    `dot -T png #{file_name}.dot > #{file_name}.png && open #{file_name}.png`
    File.delete("#{file_name}.dot")
  end
end