Class: ConfigBuilder::Loader::YAML

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

Instance Method Summary collapse

Instance Method Details

#yamldir(dir_path) ⇒ Hash

Load configuration from all files in a given directory

Parameters:

  • dir_path (String)

Returns:

  • (Hash)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/config_builder/loader/yaml.rb', line 10

def yamldir(dir_path)
  glob_path = File.join(dir_path, '*.{yml,yaml}')

  rv = {}
  Dir.glob(glob_path).each do |file|
    contents = ::YAML.load_file(file)

    if contents.is_a? Hash
      rv.merge! contents
    else
      # TODO warn on non-hash YAML
    end
  end

  rv
end

#yamlfile(file_path) ⇒ Hash

Load configuration from a file

Parameters:

  • file_path (String)

Returns:

  • (Hash)


32
33
34
# File 'lib/config_builder/loader/yaml.rb', line 32

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