Module: Itchy::Helpers::VmcatcherEnvHelper
- Defined in:
- lib/itchy/helpers/vmcatcher_env_helper.rb
Overview
Wraps static helper methods for accessing environment variables provided by vmcatcher.
Class Method Summary collapse
-
.normalize_env(env) ⇒ Hash
Converts
env
object to a hash. -
.select_from_env(env, relevant_keys) ⇒ Hash
Selects only relevant
env
entries and throws the rest away.
Class Method Details
.normalize_env(env) ⇒ Hash
Converts env
object to a hash.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/itchy/helpers/vmcatcher_env_helper.rb', line 33 def self.normalize_env(env) return env if env.is_a? Hash fail( Itchy::Errors::EnvLookupError, "'env' must be convertible to a hash!" ) unless env.respond_to?(:to_hash) env.to_hash end |
.select_from_env(env, relevant_keys) ⇒ Hash
Selects only relevant env
entries and throws the rest away. Throws Itchy::Errors::EnvLookupError if the result is empty.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/itchy/helpers/vmcatcher_env_helper.rb', line 12 def self.select_from_env(env, relevant_keys) Itchy::Log.debug "[#{name}] Looking for " \ "#{relevant_keys.inspect} in #{env.inspect}" env = env.select { |key, _| relevant_keys.include? key } if env.blank? Itchy::Log.fatal "[#{name}] No relevant information " \ "found in 'env'" fail( Itchy::Errors::EnvLookupError, 'Environment look-up failed! Result is empty!' ) end env end |