Class: Hieracles::Formats::Yaml

Inherits:
Hieracles::Format show all
Defined in:
lib/hieracles/formats/yaml.rb

Overview

format mostly useful for re-integration in param files

Instance Method Summary collapse

Methods inherited from Hieracles::Format

#initialize, #show_params

Constructor Details

This class inherits a constructor from Hieracles::Format

Instance Method Details

#add_array(output, key, leaf, params, indent) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
# 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) ⇒ Object



87
88
89
# 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) ⇒ Object



75
76
77
# 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) ⇒ Object



79
80
81
# 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) ⇒ Object



51
52
53
54
55
56
57
# 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) ⇒ Object



91
92
93
# 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) ⇒ Object



71
72
73
# 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) ⇒ Object



83
84
85
# 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) ⇒ Object



33
34
35
36
37
38
# 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) ⇒ Object



95
96
97
98
99
100
101
# 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) ⇒ Object



40
41
42
43
44
# 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(_) ⇒ Object



10
11
12
# File 'lib/hieracles/formats/yaml.rb', line 10

def facts(_)
  @node.facts.to_yaml
end

#files(_) ⇒ Object



14
15
16
# File 'lib/hieracles/formats/yaml.rb', line 14

def files(_)
  @node.files.to_yaml
end

#info(_) ⇒ Object



6
7
8
# File 'lib/hieracles/formats/yaml.rb', line 6

def info(_)
  @node.info.to_yaml
end

#mergetree(output, key, leaf, params) ⇒ Object



46
47
48
49
# 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(_) ⇒ Object



22
23
24
# File 'lib/hieracles/formats/yaml.rb', line 22

def modules(_)
  @node.modules.to_yaml
end

#params(args = nil) ⇒ Object



26
27
28
29
30
31
# 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(_) ⇒ Object



18
19
20
# File 'lib/hieracles/formats/yaml.rb', line 18

def paths(_)
  @node.paths.to_yaml
end