Module: Puppet::Util::Yaml

Defined in:
lib/puppet/util/yaml.rb

Defined Under Namespace

Classes: YamlLoadError

Constant Summary collapse

YamlLoadExceptions =
[::StandardError]

Class Method Summary collapse

Class Method Details

.dump(structure, filename) ⇒ Object



31
32
33
34
35
# File 'lib/puppet/util/yaml.rb', line 31

def self.dump(structure, filename)
  Puppet::Util.replace_file(filename, 0660) do |fh|
    YAML.dump(structure, fh)
  end
end

.load_file(filename, default_value = false, strip_classes = false) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/puppet/util/yaml.rb', line 12

def self.load_file(filename, default_value = false, strip_classes = false)
  if(strip_classes) then
    data = YAML::parse_file(filename)
    data.root.each do |o|
      if o.respond_to?(:tag=) and
         o.tag != nil and
         o.tag.start_with?("!ruby")
        o.tag = nil
      end
    end
    data.to_ruby || default_value
  else
    yaml = YAML.load_file(filename)
    yaml || default_value
  end
rescue *YamlLoadExceptions => detail
  raise YamlLoadError.new(detail.message, detail)
end