class Bundler::EnvironmentPreserver
Constants
- BUNDLER_KEYS
- BUNDLER_PREFIX
- INTENTIONALLY_NIL
Public Class Methods
new(env, keys)
click to toggle source
@param env [ENV] @param keys [Array<String>]
# File lib/bundler/environment_preserver.rb, line 23 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 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
restore()
click to toggle source
@return [Hash]
# 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