class Hieracles::Formats::Yaml

format mostly useful for re-integration in param files

Public Instance Methods

add_array(output, key, leaf, params, indent) click to toggle source
# File lib/hieracles/formats/yaml.rb, line 59
def add_array(output, key, leaf, params, indent)
  yaml = leaf.to_yaml[4..-1]
  aryaml = yaml.each_line.map do |l|
    indent + l
  end
  params[key.join('.')][:found_in].each do |k|
    output += "\n" + indent + "# " + k[:file]
  end
  output += "\n" + aryaml.join().chomp
  output        
end
add_falseclass(output, key, leaf, params, indent) click to toggle source
# File lib/hieracles/formats/yaml.rb, line 87
def add_falseclass(output, key, leaf, params, indent)
  added output, key, 'false', params
end
add_fixnum(output, key, leaf, params, indent) click to toggle source
# File lib/hieracles/formats/yaml.rb, line 75
def add_fixnum(output, key, leaf, params, indent)
  added output, key, leaf, params
end
add_float(output, key, leaf, params, indent) click to toggle source
# File lib/hieracles/formats/yaml.rb, line 79
def add_float(output, key, leaf, params, indent)
  added output, key, leaf, params
end
add_hash(output, key, leaf, params, indent) click to toggle source
# File lib/hieracles/formats/yaml.rb, line 51
def add_hash(output, key, leaf, params, indent)
  leaf.each do |k, v|
    output += "\n" + indent + k + ': '
    output = mergetree(output, key + [k], v, params)
  end
  output
end
add_nilclass(output, key, leaf, params, indent) click to toggle source
# File lib/hieracles/formats/yaml.rb, line 91
def add_nilclass(output, key, leaf, params, indent)
  added output, key, '', params
end
add_string(output, key, leaf, params, indent) click to toggle source
# File lib/hieracles/formats/yaml.rb, line 71
def add_string(output, key, leaf, params, indent)
  added output, key, leaf, params
end
add_trueclass(output, key, leaf, params, indent) click to toggle source
# File lib/hieracles/formats/yaml.rb, line 83
def add_trueclass(output, key, leaf, params, indent)
  added output, key, 'true', params
end
allparams(args = nil) click to toggle source
# File lib/hieracles/formats/yaml.rb, line 33
def allparams(args = nil)
  if args 
    args = args.join('.')
  end
  commented_yaml_tree(args, false)
end
build_list(hash, notifications, filter) click to toggle source
# File lib/hieracles/formats/yaml.rb, line 95
def build_list(hash, notifications, filter)
  if filter[0]
    hash.select { |k, e| Regexp.new(filter[0]).match k }.to_yaml
  else
    hash.to_yaml
  end
end
commented_yaml_tree(filter, without_common = true) click to toggle source
# File lib/hieracles/formats/yaml.rb, line 40
def commented_yaml_tree(filter, without_common = true)
  tree = @node.params_tree(without_common)
  params = @node.params(without_common)
  mergetree('---', [], tree, params)
end
facts(_) click to toggle source
# File lib/hieracles/formats/yaml.rb, line 10
def facts(_)
  @node.facts.to_yaml
end
files(_) click to toggle source
# File lib/hieracles/formats/yaml.rb, line 14
def files(_)
  @node.files.to_yaml
end
info(_) click to toggle source
# File lib/hieracles/formats/yaml.rb, line 6
def info(_)
  @node.info.to_yaml
end
mergetree(output, key, leaf, params) click to toggle source
# File lib/hieracles/formats/yaml.rb, line 46
def mergetree(output, key, leaf, params)
  indent = '  ' * key.count
  send("add_#{leaf.class.name.downcase}".to_sym, output, key, leaf, params, indent)
end
modules(_) click to toggle source
# File lib/hieracles/formats/yaml.rb, line 22
def modules(_)
  @node.modules.to_yaml
end
params(args = nil) click to toggle source
# File lib/hieracles/formats/yaml.rb, line 26
def params(args = nil)
  if args 
    args = args.join(' ')
  end
  commented_yaml_tree(args, true)
end
paths(_) click to toggle source
# File lib/hieracles/formats/yaml.rb, line 18
def paths(_)
  @node.paths.to_yaml
end

Private Instance Methods

added(output, key, leaf, params) click to toggle source
# File lib/hieracles/formats/yaml.rb, line 105
def added(output, key, leaf, params)
  output += leaf.to_s
  k = params["#{key.join('.')}"]
  if k
    k[:found_in].each do |i|
      output += " # " + i[:file]
    end
  end
  output
end