Module: SimpleScripting::Configuration

Extended by:
Configuration
Included in:
Configuration
Defined in:
lib/simple_scripting/configuration.rb,
lib/simple_scripting/configuration/value.rb

Defined Under Namespace

Classes: Value

Instance Method Summary collapse

Instance Method Details

#load(config_file: default_config_file, passwords_key: nil, required: []) ⇒ Object

required: list of strings. this currently support only keys outside a group; group names are not considered keys.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/simple_scripting/configuration.rb', line 16

def load(config_file: default_config_file, passwords_key: nil, required: [])
  create_empty_file(config_file) if !File.exist?(config_file)

  params = ParseConfig.new(config_file).params

  local_config_file = "#{config_file}.local"

  if File.exist?(local_config_file)
    local_params = ParseConfig.new(local_config_file).params

    params = params.merge(local_params) do |_, value, local_value|
      value.is_a?(Hash) && local_value.is_a?(Hash) ? value.merge(local_value) : local_value
    end
  end

  enforce_required_keys(params, required)

  convert_to_cool_format(OpenStruct.new, params, passwords_key)
end