123456789_123456789_123456789_123456789_123456789_

Class: Bundler::EnvironmentPreserver

Relationships & Source Files
Inherits: Object
Defined in: lib/bundler/environment_preserver.rb

Constant Summary

Class Method Summary

Instance Method Summary

Constructor Details

.new(env, keys) ⇒ EnvironmentPreserver

Parameters:

  • env (ENV)
  • keys (Array<String>)
[ GitHub ]

  
# File 'lib/bundler/environment_preserver.rb', line 23

def initialize(env, keys)
  @original = env.to_hash
  @keys = keys
  @prefix = BUNDLER_PREFIX
end

Instance Method Details

#backupHash

[ GitHub ]

  
# File 'lib/bundler/environment_preserver.rb', line 30

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

#restoreHash

[ GitHub ]

  
# File 'lib/bundler/environment_preserver.rb', line 44

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