15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/aptible/cli/renderer/text.rb', line 15
def visit(node, io)
case node
when Formatter::Root
visit(node.root, io)
when Formatter::KeyedObject
visit(node.children.fetch(node.key), io)
when Formatter::Object
node.children.each_pair do |k, c|
io.print "#{format_key(k)}:"
if c.is_a?(Formatter::List)
io.puts
visit_indented(c, io, ' ')
else
io.print ' '
visit(c, io)
end
end
when Formatter::GroupedKeyedList
enum = spacer_enumerator
node.groups.each_pair.sort_by(&:first).each do |key, group|
io.print enum.next
io.print '=== '
nodes = group.map { |n| n.children.fetch(node.key) }
visit(key, io)
output_list(nodes, io)
end
when Formatter::KeyedList
nodes = node.children.map { |n| n.children.fetch(node.key) }
output_list(nodes, io)
when Formatter::List
output_list(node.children, io)
when Formatter::Value
io.puts node.value
else
raise "Unhandled node: #{node.inspect}"
end
end
|