class Bundler::EnvironmentPreserver - bundler-1.15.4 Documentation

# class Bundler::EnvironmentPreserver

### Public Class Methods

new(env, keys) click to toggle source

@param env [ENV] @param keys [Array<String>]

    # File lib/bundler/environment_preserver.rb, line 5
    def initialize(env, keys)
      @original = env.to_hash
      @keys = keys
      @prefix = "BUNDLER_ORIG_"
    end

### Public Instance Methods

backup() click to toggle source

@return [Hash]

    # File lib/bundler/environment_preserver.rb, line 12
    def backup
      env = @original.clone
      @keys.each do |key|
        value = env[key]
        original_value = env[@prefix + key]
        if !value.nil? && !value.empty? && original_value.nil?
          env[@prefix + key] = value
        end
      end
      env
    end

restore() click to toggle source

@return [Hash]

    # File lib/bundler/environment_preserver.rb, line 25
    def restore
      env = @original.clone
      @keys.each do |key|
        value_original = env[@prefix + key]
        unless value_original.nil? || value_original.empty?
          env[key] = value_original
          env.delete(@prefix + key)
        end
      end
      env
    end