Class: Qonfig::Commands::LoadFromYAML Private

Inherits:
Base
  • Object
show all
Defined in:
lib/qonfig/commands/load_from_yaml.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 0.2.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path, strict: true) ⇒ LoadFromYAML

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of LoadFromYAML.

Options Hash (strict:):

  • (Boolean)

Since:

  • 0.2.0



25
26
27
28
# File 'lib/qonfig/commands/load_from_yaml.rb', line 25

def initialize(file_path, strict: true)
  @file_path = file_path
  @strict = strict
end

Instance Attribute Details

#file_pathString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.2.0



12
13
14
# File 'lib/qonfig/commands/load_from_yaml.rb', line 12

def file_path
  @file_path
end

#strictBoolean (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.2.0



18
19
20
# File 'lib/qonfig/commands/load_from_yaml.rb', line 18

def strict
  @strict
end

Instance Method Details

#call(settings) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/qonfig/commands/load_from_yaml.rb', line 37

def call(settings)
  yaml_data = Qonfig::Loaders::YAML.load_file(file_path, fail_on_unexist: strict)

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

  yaml_based_settings = build_data_set_class(yaml_data).new.settings

  settings.__append_settings__(yaml_based_settings)
end