lib/hieracles/formats/plain.rb in hieracles-0.2.0 vs lib/hieracles/formats/plain.rb in hieracles-0.2.1
- old
+ new
@@ -8,15 +8,36 @@
def initialize(node)
@index = {}
super(node)
end
- def info(_)
+ def info(filter)
+ build_list(@node.info, @node.notifications, filter)
+ end
+
+ def facts(filter)
+ build_list(@node.facts, @node.notifications, filter)
+ end
+
+ def build_list(hash, notifications, filter)
back = ''
- length = max_key_length(@node.info) + 2
- @node.info.each do |k, v|
+ 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
+
+ def build_notifications(notifications)
+ back = "\n"
+ notifications.each do |v|
+ back << "*** #{v.source}: #{v.message} ***\n"
+ end
+ back << "\n"
back
end
def files(_)
@node.files.join("\n") + "\n"