Class: ConfigManager::YAMLPropertiesLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/configmanager/loaders.rb

Overview

Loads properties from a YAML file.

Class Method Summary collapse

Class Method Details

.load_properties(file_path, configuration) ⇒ Hash

Loads properties from the specified YAML file. This is the default loader.

Parameters:

  • file_path (String)

    the file to load.

  • configuration (Configuration)

    the configuration to add the loaded properties to.

Returns:

  • (Hash)

    the properties read from the file.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/configmanager/loaders.rb', line 16

def self.load_properties(file_path, configuration)
  require "yaml"
  file_path = File.expand_path(file_path)
  properties = YAML.load_file(file_path)
  files_to_import = properties.delete("import") { [] }
  files_to_import = [files_to_import] unless files_to_import.kind_of?(Array)
  configuration.add_properties(properties)
  # Load any referenced files too.
  file_dir = File.dirname(file_path)
  files_to_import.each { |file_to_import| load_properties(File.expand_path(file_to_import, file_dir), configuration) }
end