Class: Terraspace::All::Grapher
Instance Method Summary
collapse
#logger
#cache_dirs, #dirs, #extract_stack_name, #local_paths, #mod_names, #select_stack?, #stack_names, #with_each_mod
Methods inherited from Base
#initialize
Instance Method Details
#build_tree_data(nodes) ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/terraspace/all/grapher.rb', line 37
def build_tree_data(nodes)
if nodes.size == 1
tree_data(nodes.first)
else
root = Terraspace::Dependency::Node.new('.')
nodes.each { |node| node.parent!(root) }
tree_data(root)
end
end
|
#draw(nodes) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/terraspace/all/grapher.rb', line 66
def draw(nodes)
path, filename = nil, filename() digraph do
node_attribs << color('"#b6d7a8"') << filled << fontcolor("white")
edge_attribs << color('"#999999"') << filled
nodes.each do |parent|
if parent.highlighted?
node(parent.name)
else
node(parent.name).attributes << color('"#A4C2F4"')
end
parent.children.each do |child|
edge(parent.name, child.name)
end
end
FileUtils.mkdir_p(File.dirname(filename))
save(filename, "png")
path = "#{filename}.png"
end
logger.info "Graph saved to #{Terraspace::Util.pretty_path(path)}"
open(path)
end
|
#run ⇒ Object
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/terraspace/all/grapher.rb', line 9
def run
check_graphviz!
logger.info "Building graph..."
graph = build_graph
if @options[:format] == "text"
text(graph.top_nodes)
else
draw(graph.nodes)
end
end
|
#text(nodes) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/terraspace/all/grapher.rb', line 29
def text(nodes)
Rainbow.enabled = false unless @options[:full]
data = build_tree_data(nodes)
Rainbow.enabled = true unless @options[:full]
tree = TTY::Tree.new(data)
logger.info tree.render
end
|
#text_name(node) ⇒ Object
62
63
64
|
# File 'lib/terraspace/all/grapher.rb', line 62
def text_name(node)
node.highlighted? ? node.name.bright : node.name
end
|
#tree_data(parent, data = {}) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/terraspace/all/grapher.rb', line 47
def tree_data(parent, data={})
parent_name = text_name(parent)
data[parent_name] ||= []
parent.children.each do |child|
child_name = text_name(child)
if child.children.empty? data[parent_name] << child_name
else
next_data = { child_name => [] }
data[parent_name] << tree_data(child, next_data)
end
end
data
end
|