class Checkoff::EnvFallbackConfigLoader
Use the provided config from a YAML file, and fall back to env variable if it's not populated for a key'
Public Class Methods
new(config, sym, yaml_filename)
click to toggle source
# File lib/checkoff/config_loader.rb, line 10 def initialize(config, sym, yaml_filename) @config = config @envvar_prefix = sym.upcase @yaml_filename = yaml_filename end
Public Instance Methods
[](key)
click to toggle source
# File lib/checkoff/config_loader.rb, line 16 def [](key) config_value = @config[key] return config_value unless config_value.nil? ENV[envvar_name(key)] end
fetch(key)
click to toggle source
# File lib/checkoff/config_loader.rb, line 23 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
Private Instance Methods
envvar_name(key)
click to toggle source
# File lib/checkoff/config_loader.rb, line 33 def envvar_name(key) "#{@envvar_prefix}__#{key.upcase}" end