In Files

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

Class/Module Index [+]

Quicksearch

Bundler::EnvironmentPreserver

Public Class Methods

env_to_hash(env) click to toggle source
 
               # File bundler/environment_preserver.rb, line 23
def self.env_to_hash(env)
  to_hash = env.to_hash
  return to_hash unless Gem.win_platform?

  to_hash.each_with_object({}) {|(k,v), a| a[k.upcase] = v }
end
            
from_env() click to toggle source
 
               # File bundler/environment_preserver.rb, line 19
def self.from_env
  new(env_to_hash(ENV), BUNDLER_KEYS)
end
            
new(env, keys) click to toggle source

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

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

Public Instance Methods

backup() click to toggle source

@return [Hash]

 
               # File bundler/environment_preserver.rb, line 52
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
            
replace_with_backup() click to toggle source

Replaces `ENV` with the bundler environment variables backed up

 
               # File bundler/environment_preserver.rb, line 39
def replace_with_backup
  ENV.replace(backup) unless Gem.win_platform?

  # Fallback logic for Windows below to workaround
  # https://bugs.ruby-lang.org/issues/16798. Can be dropped once all
  # supported rubies include the fix for that.

  ENV.clear

  backup.each {|k, v| ENV[k] = v }
end
            
restore() click to toggle source

@return [Hash]

 
               # File bundler/environment_preserver.rb, line 66
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