Class: PDK::Config::YAML
Overview
Parses a YAML document.
Instance Attribute Summary
Attributes inherited from Namespace
Instance Method Summary collapse
- #parse_file(filename) ⇒ Object
-
#serialize_data(data) ⇒ Object
Serializes object data into a YAML string.
Methods inherited from Namespace
#[], #[]=, #child_namespace?, #fetch, #include_in_parent?, #initialize, #mount, #namespace, #read_only!, #resolve, #setting, #to_h
Constructor Details
This class inherits a constructor from PDK::Config::Namespace
Instance Method Details
#parse_file(filename) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pdk/config/yaml.rb', line 9 def parse_file(filename) raise unless block_given? data = load_data(filename) return if data.nil? || data.empty? require 'yaml' data = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0.pre1') ::YAML.safe_load(data, permitted_classes: [Symbol], permitted_symbols: [], aliases: true) else ::YAML.safe_load(data, [Symbol], [], true) end return if data.nil? data.each { |k, v| yield k, PDK::Config::Setting.new(k, self, v) } rescue Psych::SyntaxError => e raise PDK::Config::LoadError, format('Syntax error when loading %{file}: %{error}', file: filename, error: "#{e.problem} #{e.context}") rescue Psych::DisallowedClass => e raise PDK::Config::LoadError, format('Unsupported class in %{file}: %{error}', file: filename, error: e.) end |
#serialize_data(data) ⇒ Object
Serializes object data into a YAML string.
34 35 36 37 38 |
# File 'lib/pdk/config/yaml.rb', line 34 def serialize_data(data) require 'yaml' ::YAML.dump(data) end |