Class: Checkoff::Internal::EnvFallbackConfigLoader
- Inherits:
-
Object
- Object
- Checkoff::Internal::EnvFallbackConfigLoader
- Defined in:
- lib/checkoff/internal/config_loader.rb
Overview
Use the provided config from a YAML file, and fall back to env variable if it’s not populated for a key’
Instance Method Summary collapse
- #[](key) ⇒ Object
- #fetch(key) ⇒ Object
-
#initialize(config, sym, yaml_filename) ⇒ EnvFallbackConfigLoader
constructor
A new instance of EnvFallbackConfigLoader.
Constructor Details
#initialize(config, sym, yaml_filename) ⇒ EnvFallbackConfigLoader
Returns a new instance of EnvFallbackConfigLoader.
14 15 16 17 18 |
# File 'lib/checkoff/internal/config_loader.rb', line 14 def initialize(config, sym, yaml_filename) @config = config @envvar_prefix = sym.upcase @yaml_filename = yaml_filename end |
Instance Method Details
#[](key) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/checkoff/internal/config_loader.rb', line 22 def [](key) config_value = @config[key] return config_value unless config_value.nil? # @sg-ignore ENV.fetch(envvar_name(key), nil) end |
#fetch(key) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/checkoff/internal/config_loader.rb', line 32 def fetch(key) out = self[key] return out unless out.nil? raise KeyError, "Please configure either the #{key} key in #{@yaml_filename} or set #{envvar_name(key)}" end |