module Envvar
Constants
- DEFAULTS_KEY
- REQUIRED_KEY
- VERSION
Public Class Methods
load(file_path, env = (ENV['RACK_ENV'] || :development))
click to toggle source
# File lib/envvar.rb, line 11 def self.load(file_path, env = (ENV['RACK_ENV'] || :development)) config = YAML.load(ERB.new(open(file_path).read).result) set_environment(config, env.to_s) set_defaults(config) check_required(config) end
Private Class Methods
check_from_hash(config)
click to toggle source
# File lib/envvar.rb, line 48 def self.check_from_hash(config) config.each do |var| if ENV[var].nil? raise EnvironmentError.new("Required var #{var} not found in ENV hash") end end end
check_required(config)
click to toggle source
# File lib/envvar.rb, line 34 def self.check_required(config) return if config[REQUIRED_KEY].nil? check_from_hash(config[REQUIRED_KEY]) end
set_defaults(config)
click to toggle source
# File lib/envvar.rb, line 22 def self.set_defaults(config) return if config[DEFAULTS_KEY].nil? set_from_hash(config[DEFAULTS_KEY]) end
set_environment(config, env)
click to toggle source
# File lib/envvar.rb, line 28 def self.set_environment(config, env) return if config[env].nil? set_from_hash(config[env]) end
set_from_hash(config)
click to toggle source
# File lib/envvar.rb, line 40 def self.set_from_hash(config) config.each do |var, default| if ENV[var].nil? ENV[var] = default.to_s end end end