Module: R10K::Util::ExecEnv

Defined in:
lib/r10k/util/exec_env.rb

Overview

Utility methods for dealing with environment variables

Class Method Summary collapse

Class Method Details

.reset(env) ⇒ void

This method returns an undefined value.

Swap out all environment settings

Parameters:

  • env (Hash)

    The new environment to use



12
13
14
15
16
17
18
19
20
# 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) ⇒ void

This method returns an undefined value.

Add the specified settings to the env for the supplied block

Parameters:

  • env (Hash)

    The values to add to the environment

  • block (Proc)

    The code to call with the modified environnment



27
28
29
30
31
32
33
# 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