Class: Qonfig::Commands::Definition::LoadFromJSON Private

Inherits:
Base
  • Object
show all
Defined in:
lib/qonfig/commands/definition/load_from_json.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.5.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

inheritable=, inheritable?, #inheritable?, inherited

Constructor Details

#initialize(file_path, strict: true) ⇒ LoadFromJSON

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 LoadFromJSON.

Parameters:

  • file_path (String, Pathname)
  • strict (Hash) (defaults to: true)

    a customizable set of options

Options Hash (strict:):

  • (Boolean)

Since:

  • 0.5.0



26
27
28
29
# File 'lib/qonfig/commands/definition/load_from_json.rb', line 26

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

Instance Attribute Details

#file_pathString, Pathname (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.

Returns:

  • (String, Pathname)

Since:

  • 0.5.0



13
14
15
# File 'lib/qonfig/commands/definition/load_from_json.rb', line 13

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.

Returns:

  • (Boolean)

Since:

  • 0.5.0



19
20
21
# File 'lib/qonfig/commands/definition/load_from_json.rb', line 19

def strict
  @strict
end

Instance Method Details

#call(data_set, 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.

Parameters:

Raises:

Since:

  • 0.5.0



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

def call(data_set, settings)
  json_data = Qonfig::Loaders::JSON.load_file(file_path, fail_on_unexist: strict)

  raise(
    Qonfig::IncompatibleJSONStructureError,
    'JSON object must be a hash-like structure'
  ) unless json_data.is_a?(Hash)

  json_based_settings = build_data_set_klass(json_data).new.settings
  settings.__append_settings__(json_based_settings)
end