Sha256: 232e569091b9ed16df389a0c8dc5c7b54656eeb1bd2b67c81d31ae360196a754

Contents?: true

Size: 1.33 KB

Versions: 8

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

# @api private
# @since 0.2.0
class Qonfig::Commands::Definition::LoadFromYAML < Qonfig::Commands::Base
  # @since 0.19.0
  self.inheritable = true

  # @return [String, Pathname]
  #
  # @api private
  # @since 0.2.0
  attr_reader :file_path

  # @return [Boolean]
  #
  # @api private
  # @since 0.2.0
  attr_reader :strict

  # @param file_path [String, Pathname]
  # @option strict [Boolean]
  #
  # @api private
  # @since 0.2.0
  def initialize(file_path, strict: true)
    @file_path = file_path
    @strict = strict
  end

  # @param data_set [Qonfig::DataSet]
  # @param settings [Qonfig::Settings]
  # @return [void]
  #
  # @raise [Qonfig::IncompatibleYAMLStructureError]
  #
  # @api private
  # @since 0.2.0
  def call(data_set, settings)
    yaml_data = Qonfig::Loaders::YAML.load_file(file_path, fail_on_unexist: strict)

    raise(
      Qonfig::IncompatibleYAMLStructureError,
      'YAML content must be a hash-like structure'
    ) unless yaml_data.is_a?(Hash)

    yaml_based_settings = build_data_set_klass(yaml_data).new.settings
    settings.__append_settings__(yaml_based_settings)
  end

  private

  # @param yaml_data [Hash]
  # @return [Class<Qonfig::DataSet>]
  #
  # @api private
  # @since 0.2.0
  def build_data_set_klass(yaml_data)
    Qonfig::DataSet::ClassBuilder.build_from_hash(yaml_data)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
qonfig-0.28.0 lib/qonfig/commands/definition/load_from_yaml.rb
qonfig-0.27.0 lib/qonfig/commands/definition/load_from_yaml.rb
qonfig-0.26.0 lib/qonfig/commands/definition/load_from_yaml.rb
qonfig-0.25.0 lib/qonfig/commands/definition/load_from_yaml.rb
qonfig-0.24.1 lib/qonfig/commands/definition/load_from_yaml.rb
qonfig-0.24.0 lib/qonfig/commands/definition/load_from_yaml.rb
qonfig-0.23.0 lib/qonfig/commands/definition/load_from_yaml.rb
qonfig-0.22.0 lib/qonfig/commands/definition/load_from_yaml.rb