Module: WithEnv

Extended by:
WithEnv
Included in:
WithEnv
Defined in:
lib/with_env.rb,
lib/with_env/version.rb

Constant Summary collapse

VERSION =
"1.1.0"

Instance Method Summary collapse

Instance Method Details

#with_env(env, &blk) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/with_env.rb', line 6

def with_env(env, &blk)
  before = ENV.to_h.dup
  env.each { |k, v| ENV[k] = v }
  yield
ensure
  ENV.replace(before)
end

#without_env(*keys, &blk) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/with_env.rb', line 14

def without_env(*keys, &blk)
  before = ENV.to_h.dup
  keys.flatten.each { |k| ENV.delete(k) }
  yield
ensure
  ENV.replace(before)
end