Sha256: 914849430c42071d634bda6c8095096c919701fdeddbbd03a003927006ce2727

Contents?: true

Size: 868 Bytes

Versions: 80

Compression:

Stored size: 868 Bytes

Contents

module R10K
  module Util

    # Utility methods for dealing with environment variables
    module ExecEnv
      module_function

      # Swap out all environment settings
      #
      # @param env [Hash] The new environment to use
      # @return [void]
      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

      # 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]
      def withenv(env, &block)
        original = ENV.to_hash
        reset(original.merge(env))
        block.call
      ensure
        reset(original)
      end
    end
  end
end

Version data entries

80 entries across 80 versions & 2 rubygems

Version Path
r10k-3.10.0 lib/r10k/util/exec_env.rb
r10k-3.9.3 lib/r10k/util/exec_env.rb
r10k-3.9.2 lib/r10k/util/exec_env.rb
r10k-3.9.1 lib/r10k/util/exec_env.rb
r10k-3.9.0 lib/r10k/util/exec_env.rb
r10k-3.8.0 lib/r10k/util/exec_env.rb
r10k-3.7.0 lib/r10k/util/exec_env.rb
r10k-3.6.0 lib/r10k/util/exec_env.rb
r10k-2.6.9 lib/r10k/util/exec_env.rb
r10k-3.5.2 lib/r10k/util/exec_env.rb
r10k-3.5.1 lib/r10k/util/exec_env.rb
r10k-3.5.0 lib/r10k/util/exec_env.rb
r10k-3.4.1 lib/r10k/util/exec_env.rb
r10k-2.6.8 lib/r10k/util/exec_env.rb
r10k-3.4.0 lib/r10k/util/exec_env.rb
r10k-3.3.3 lib/r10k/util/exec_env.rb
r10k-3.2.3 lib/r10k/util/exec_env.rb
r10k-2.6.7 lib/r10k/util/exec_env.rb
r10k-3.3.2 lib/r10k/util/exec_env.rb
r10k-3.3.1 lib/r10k/util/exec_env.rb