module R10K::Util::ExecEnv

Utility methods for dealing with environment variables

Public Instance Methods

reset(env) click to toggle source

Swap out all environment settings

@param env [Hash] The new environment to use @return [void]

# File lib/r10k/util/exec_env.rb, line 12
def reset(env)
  env.each_pair do |key, value|
    ENV[key] = value
  end

  (ENV.keys - env.keys).each do |key|
    ENV.delete(key)
  end
end
withenv(env, &block) click to toggle source

Add the specified settings to the env for the supplied block

@param env [Hash] The values to add to the environment @param block [Proc] The code to call with the modified environnment @return [void]

# File lib/r10k/util/exec_env.rb, line 27
def withenv(env, &block)
  original = ENV.to_hash
  reset(original.merge(env))
  block.call
ensure
  reset(original)
end