In Files

  • bundler.rb
  • bundler/environment_preserver.rb
  • bundler/shared_helpers.rb

Parent

Class/Module Index [+]

Quicksearch

Bundler::EnvironmentPreserver

Public Class Methods

new(env, keys) click to toggle source

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

 
               # File bundler/environment_preserver.rb, line 22
def initialize(env, keys)
  @original = env.to_hash
  @keys = keys
  @prefix = BUNDLER_PREFIX
end
            

Public Instance Methods

backup() click to toggle source

@return [Hash]

 
               # File bundler/environment_preserver.rb, line 29
def backup
  env = @original.clone
  @keys.each do |key|
    value = env[key]
    if !value.nil? && !value.empty?
      env[@prefix + key] ||= value
    elsif value.nil?
      env[@prefix + key] ||= INTENTIONALLY_NIL
    end
  end
  env
end
            
restore() click to toggle source

@return [Hash]

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