class Qonfig::Commands::Definition::LoadFromYAML

@api private @since 0.2.0

Attributes

file_path[R]

@return [String, Pathname]

@api private @since 0.2.0

strict[R]

@return [Boolean]

@api private @since 0.2.0

Public Class Methods

new(file_path, strict: true) click to toggle source

@param file_path [String, Pathname] @option strict [Boolean]

@api private @since 0.2.0

# File lib/qonfig/commands/definition/load_from_yaml.rb, line 26
def initialize(file_path, strict: true)
  @file_path = file_path
  @strict = strict
end

Public Instance Methods

call(data_set, settings) click to toggle source

@param data_set [Qonfig::DataSet] @param settings [Qonfig::Settings] @return [void]

@raise [Qonfig::IncompatibleYAMLStructureError]

@api private @since 0.2.0

# File lib/qonfig/commands/definition/load_from_yaml.rb, line 39
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 Instance Methods

build_data_set_klass(yaml_data) click to toggle source

@param yaml_data [Hash] @return [Class<Qonfig::DataSet>]

@api private @since 0.2.0

# File lib/qonfig/commands/definition/load_from_yaml.rb, line 58
def build_data_set_klass(yaml_data)
  Qonfig::DataSet::ClassBuilder.build_from_hash(yaml_data)
end