Sha256: a2616239001cfc706128c3abb7d8cc0a73ea8f896722936a9afbb8e9af13f4fd

Contents?: true

Size: 1.09 KB

Versions: 10

Compression:

Stored size: 1.09 KB

Contents

require 'pdk'

module PDK
  class Config
    # Parses a YAML document.
    #
    # @see PDK::Config::Namespace.parse_file
    class YAML < Namespace
      def parse_file(filename)
        raise unless block_given?
        data = load_data(filename)
        return if data.nil? || data.empty?

        require 'yaml'

        data = ::YAML.safe_load(data, [Symbol], [], true)
        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, _('Syntax error when loading %{file}: %{error}') % {
          file:  filename,
          error: "#{e.problem} #{e.context}",
        }
      rescue Psych::DisallowedClass => e
        raise PDK::Config::LoadError, _('Unsupported class in %{file}: %{error}') % {
          file:  filename,
          error: e.message,
        }
      end

      # Serializes object data into a YAML string.
      #
      # @see PDK::Config::Namespace.serialize_data
      def serialize_data(data)
        require 'yaml'

        ::YAML.dump(data)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
pdk-2.2.0 lib/pdk/config/yaml.rb
pdk-2.1.1 lib/pdk/config/yaml.rb
pdk-2.1.0 lib/pdk/config/yaml.rb
pdk-2.0.0 lib/pdk/config/yaml.rb
pdk-1.18.1 lib/pdk/config/yaml.rb
pdk-1.18.0 lib/pdk/config/yaml.rb
pdk-1.17.0 lib/pdk/config/yaml.rb
pdk-1.16.0 lib/pdk/config/yaml.rb
pdk-1.15.0 lib/pdk/config/yaml.rb
pdk-1.14.1 lib/pdk/config/yaml.rb