Class: UltraSettings::YamlConfig
- Inherits:
-
Object
- Object
- UltraSettings::YamlConfig
- 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:
“‘yaml shared:
foo:
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:
“‘ruby
"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
-
#initialize(path, environment) ⇒ YamlConfig
constructor
Initialize a YAML configuration loader.
-
#to_h ⇒ Hash
Convert the loaded configuration to a hash.
Constructor Details
#initialize(path, environment) ⇒ YamlConfig
Initialize a YAML configuration loader.
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_h ⇒ Hash
Convert the loaded configuration to a hash.
48 49 50 |
# File 'lib/ultra_settings/yaml_config.rb', line 48 def to_h @config end |