Class: UltraSettings::YamlConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/ultra_settings/yaml_config.rb

Overview

Helper class to load YAML configuration files. Any ERB markup in the YAML file will be evaluated. The YAML file should be structured like this:

shared:
  foo: bar
  bar: baz

development:
  bar: qux
  biz: buz

test:
  bar: qix
  biz: biz

The section with the key matching the environment name is merged into the shared section. In this example, the development environment would have the following configuration:

{
  "foo" => "bar",
  "bar" => "qux",
  "biz" => "buz"
}

In addition, the keys are flattened into a one level deep hash with dots separating the keys.

Instance Method Summary collapse

Constructor Details

#initialize(path, environment) ⇒ YamlConfig

Initialize a YAML configuration loader.

Parameters:

  • path (String, Pathname)

    The path to the YAML configuration file.

  • environment (String)

    The environment section to load from the YAML file.



40
41
42
43
# File 'lib/ultra_settings/yaml_config.rb', line 40

def initialize(path, environment)
  yaml = load_yaml(path)
  @config = environment_config(yaml, environment)
end

Instance Method Details

#to_hHash

Convert the loaded configuration to a hash.

Returns:

  • (Hash)

    The flattened configuration hash.



48
49
50
# File 'lib/ultra_settings/yaml_config.rb', line 48

def to_h
  @config
end