Class: Checkoff::Internal::EnvFallbackConfigLoader
- Inherits:
-
Object
- Object
- Checkoff::Internal::EnvFallbackConfigLoader
- Defined in:
- lib/checkoff/internal/config_loader.rb,
sig/checkoff.rbs
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
@param
key. -
#envvar_name(key) ⇒ String
@param
key. -
#fetch(key) ⇒ Object
@param
key. -
#initialize(config, sym, yaml_filename) ⇒ EnvFallbackConfigLoader
constructor
@param
config.
Constructor Details
#initialize(config, sym, yaml_filename) ⇒ EnvFallbackConfigLoader
@param config
@param sym
@param yaml_filename
15 16 17 18 19 |
# File 'lib/checkoff/internal/config_loader.rb', line 15 def initialize(config, sym, yaml_filename) @config = config @envvar_prefix = sym.upcase @yaml_filename = yaml_filename end |
Instance Method Details
#[](key) ⇒ Object
@param key
23 24 25 26 27 28 |
# File 'lib/checkoff/internal/config_loader.rb', line 23 def [](key) config_value = @config[key] return config_value unless config_value.nil? ENV.fetch(envvar_name(key), nil) end |
#envvar_name(key) ⇒ String
@param key
44 45 46 |
# File 'lib/checkoff/internal/config_loader.rb', line 44 def envvar_name(key) "#{@envvar_prefix}__#{key.upcase}" end |
#fetch(key) ⇒ Object
@param key
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 |