class Hieracles::Formats::Plain

format accepting colors for display in the terminal

Public Class Methods

new(node) click to toggle source
Calls superclass method Hieracles::Format.new
# File lib/hieracles/formats/plain.rb, line 8
def initialize(node)
  @index = {}
  super(node)
end

Public Instance Methods

build_head(without_common) click to toggle source
# 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_line_item(key, value) click to toggle source
# File lib/hieracles/formats/plain.rb, line 68
def build_line_item(key, value)
  if value[:overriden]
    "[-] #{key} #{value[:value]}\n" +
    build_overriden(key, value[:found_in])
  else
    filecolor_index = @index[value[:file]]
    "[#{filecolor_index}] #{key} #{value[:value]}\n"
  end
end
build_list(hash, notifications, filter) click to toggle source
# 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) click to toggle source
# File lib/hieracles/formats/plain.rb, line 88
def build_modules_line(key, value)
  length = max_key_length(@node.modules) + 3
  format("%-#{length}s %s\n", key, value)
end
build_notifications(notifications) click to toggle source
# 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_overriden(key, found_in) click to toggle source
# File lib/hieracles/formats/plain.rb, line 78
def build_overriden(key, found_in)
  back = ''
  found_in.each do |v|
    filecolor_index = @index[v[:file]]
    back << "    [#{filecolor_index}] #{key} #{v[:value]}\n"
  end
  back
end
build_params_line(key, value, filter) click to toggle source
# File lib/hieracles/formats/plain.rb, line 60
def build_params_line(key, value, filter)
  output = ''
  if !filter || Regexp.new(filter).match(key)
    output << build_line_item(key, value)
  end
  output
end
facts(filter) click to toggle source
# File lib/hieracles/formats/plain.rb, line 17
def facts(filter)
  build_list(@node.facts, @node.notifications, filter)
end
files(_) click to toggle source
# File lib/hieracles/formats/plain.rb, line 43
def files(_)
  @node.files.join("\n") + "\n"
end
info(filter) click to toggle source
# File lib/hieracles/formats/plain.rb, line 13
def info(filter)
  build_list(@node.info, @node.notifications, filter)
end
paths(_) click to toggle source
# File lib/hieracles/formats/plain.rb, line 47
def paths(_)
  @node.paths.join("\n") + "\n"
end