Class: Configurate::Provider::YAML

Inherits:
StringHash show all
Defined in:
lib/configurate/provider/yaml.rb

Overview

This provider tries to open a YAML file and does nested lookups in it.

Instance Method Summary collapse

Methods inherited from StringHash

#lookup_path

Methods inherited from Base

#lookup

Constructor Details

#initialize(file, namespace: nil, required: true, raise_on_missing: false) ⇒ YAML

Returns a new instance of YAML.

Parameters:

  • file (String)

    the path to the file

  • namespace (String) (defaults to: nil)

    optionally set this as the root

  • required (Boolean) (defaults to: true)

    whether or not to raise an error if the file or the namespace, if given, is not found. Defaults to true.

  • raise_on_missing (Boolean) (defaults to: false)

    whether to raise MissingSetting if a setting can’t be provided. Defaults to false.

Raises:

  • (ArgumentError)

    if the namespace isn’t found in the file

  • (Errno:ENOENT)

    if the file isn’t found



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/configurate/provider/yaml.rb', line 18

def initialize file, namespace: nil, required: true, raise_on_missing: false
  super(::YAML.load_file(file),
    namespace:        namespace,
    required:         required,
    raise_on_missing: raise_on_missing,
    source:           file
  )
rescue Errno::ENOENT => e
  warn "WARNING: Configuration file #{file} not found, ensure it's present"
  raise e if required
end