Class: Hieracles::Formats::Plain
Overview
format accepting colors for display in the terminal
Instance Method Summary
collapse
Methods included from Utils
#deep_sort, #local_merge!, #max_key_length, #sym_keys, #to_deep_hash, #to_shallow_hash
#allparams, #modules, #params, #show_params
Constructor Details
#initialize(node) ⇒ Plain
Returns a new instance of Plain.
8
9
10
11
|
# File 'lib/hieracles/formats/plain.rb', line 8
def initialize(node)
@index = {}
super(node)
end
|
Instance Method Details
#build_head(without_common) ⇒ Object
51
52
53
54
55
56
57
58
|
# File 'lib/hieracles/formats/plain.rb', line 51
def build_head(without_common)
output = "[-] (merged)\n"
@node.files(without_common).each_with_index do |f, i|
output << "[#{i}] #{f}\n"
@index[f] = i
end
"#{output}\n"
end
|
#build_list(hash, notifications, filter) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/hieracles/formats/plain.rb', line 21
def build_list(hash, notifications, filter)
back = ''
back << build_notifications(notifications) if notifications
if filter[0]
hash.select! { |k, v| Regexp.new(filter[0]).match(k) }
end
length = max_key_length(hash) + 2
hash.each do |k, v|
back << format("%-#{length}s %s\n", k, v)
end
back
end
|
#build_modules_line(key, value) ⇒ Object
80
81
82
83
|
# File 'lib/hieracles/formats/plain.rb', line 80
def build_modules_line(key, value)
length = max_key_length(@node.modules) + 3
format("%-#{length}s %s\n", key, value)
end
|
#build_notifications(notifications) ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/hieracles/formats/plain.rb', line 34
def build_notifications(notifications)
back = "\n"
notifications.each do |v|
back << "*** #{v.source}: #{v.message} ***\n"
end
back << "\n"
back
end
|
#build_params_line(key, value, filter) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/hieracles/formats/plain.rb', line 60
def build_params_line(key, value, filter)
output = ''
if !filter || Regexp.new(filter).match(key)
first = value.pop
filecolor_index = @index[first[:file]]
if is_merged? first
output << "[-] #{key} #{first[:merged]}\n"
output << " [#{filecolor_index}] #{key} #{first[:value]}\n"
else
output << "[#{filecolor_index}] #{key} #{first[:value]}\n"
end
while value.count > 0
overriden = value.pop
filecolor_index = @index[overriden[:file]]
output << " [#{filecolor_index}] #{key} #{overriden[:value]}\n"
end
end
output
end
|
#facts(filter) ⇒ Object
17
18
19
|
# File 'lib/hieracles/formats/plain.rb', line 17
def facts(filter)
build_list(@node.facts, @node.notifications, filter)
end
|
#files(_) ⇒ Object
43
44
45
|
# File 'lib/hieracles/formats/plain.rb', line 43
def files(_)
@node.files.join("\n") + "\n"
end
|
#info(filter) ⇒ Object
13
14
15
|
# File 'lib/hieracles/formats/plain.rb', line 13
def info(filter)
build_list(@node.info, @node.notifications, filter)
end
|
#paths(_) ⇒ Object
47
48
49
|
# File 'lib/hieracles/formats/plain.rb', line 47
def paths(_)
@node.paths.join("\n") + "\n"
end
|