module Nuggets::Env::SetMixin

Public Instance Methods

set([env[, clear]]) → aHash click to toggle source
set([env[, clear]]) { ... } → anObject

Overrides ENV with env, clearing it beforehand if clear is true. If a block is given, restores ENV to its original state afterwards and returns the result of the block; otherwise returns the original ENV as a hash.

# File lib/nuggets/env/set_mixin.rb, line 38
def set(env = {}, clear = true)
  old_env = to_hash

  self.clear if clear

  env.each { |key, value|
    key = key.to_s.upcase unless key.is_a?(::String)
    value = value.to_s unless value.is_a?(::String)

    self[key] = value
  }

  block_given? ? yield : old_env
ensure
  set(old_env) if old_env && block_given?
end
Also aliased as: without
with([env[, clear]]) { ... } → anObject click to toggle source

Temporarily overrides ENV with env for the block execution. See set.

# File lib/nuggets/env/set_mixin.rb, line 61
def with(env = {}, clear = false)
  set(env, clear) { yield }
end
without(env = {}, clear = true)
Alias for: set