On this page
class Bundler::EnvironmentPreserver
Constants
- BUNDLER_KEYS
- BUNDLER_PREFIX
- INTENTIONALLY_NIL
Public Class Methods
# File lib/bundler/environment_preserver.rb, line 23
def initialize(env, keys)
@original = env.to_hash
@keys = keys
@prefix = BUNDLER_PREFIX
end
@param env [ENV] @param keys [Array<String>]
Public Instance Methods
# 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
@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
@return [Hash]
Ruby Core © 1993–2017 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.