Class: ConfigBuilder::Loader::YAML

Inherits:
Object
  • Object
show all
Defined in:
lib/config_builder/loader/yaml.rb

Direct Known Subclasses

YAML_ERB

Instance Method Summary collapse

Instance Method Details

#yamldir(path) ⇒ Hash #yamldir(paths) ⇒ Hash

Load configuration from YAML files in one or more directories

Overloads:

  • #yamldir(path) ⇒ Hash

    Parameters:

    • path (String)

      A directory path containing YAML files

  • #yamldir(paths) ⇒ Hash

    Parameters:

    • paths (Array<String>)

      A list of directory paths containing YAML files

Returns:

  • (Hash)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/config_builder/loader/yaml.rb', line 14

def yamldir(input)
  dirs = Array(input)

  files = dirs.map do |dir|
    pattern = File.join(dir, '*.{yml,yaml}')
    Dir.glob(pattern)
  end.flatten

  rv = {}

  files.each do |file|
    contents = yamlfile(file)
    if contents.is_a? Hash
      rv = DeepMerge::deep_merge!(contents, rv, {:preserve_unmergables => false})
    end
  end

  rv
end

#yamlfile(file_path) ⇒ Hash

Load configuration from a file

Parameters:

  • file_path (String)

Returns:

  • (Hash)


39
40
41
# File 'lib/config_builder/loader/yaml.rb', line 39

def yamlfile(file_path)
  ::YAML.load_file(file_path)
end