Module: Puppet::Util::Execution

Included in:
Provider::Exec
Defined in:
lib/vendor/puppet/util/execution.rb

Class Method Summary collapse

Class Method Details

.withenv(hash) ⇒ Object

Run some code with a specific environment. Resets the environment back to what it was at the end of the code.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/vendor/puppet/util/execution.rb', line 6

def withenv(hash)
  saved = ENV.to_hash
  hash.each do |name, val|
    ENV[name.to_s] = val
  end

  yield
ensure
  ENV.clear
  saved.each do |name, val|
    ENV[name] = val
  end
end