Class: ConfigBuilder::Loader::YAML
- Inherits:
-
Object
- Object
- ConfigBuilder::Loader::YAML
- Defined in:
- lib/config_builder/loader/yaml.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#yamldir(input) ⇒ Hash
Load configuration from YAML files in one or more directories.
-
#yamlfile(file_path) ⇒ Hash
Load configuration from a file.
Instance Method Details
#yamldir(path) ⇒ Hash #yamldir(paths) ⇒ Hash
Load configuration from YAML files in one or more directories
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
39 40 41 |
# File 'lib/config_builder/loader/yaml.rb', line 39 def yamlfile(file_path) ::YAML.load_file(file_path) end |