summaryrefslogtreecommitdiff
path: root/lib/bundler/environment_preserver.rb
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2020-05-08 14:19:04 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-05-13 07:54:37 +0900
commit0e60b59d5884edb8f9aea023efd9b24f1ff02049 (patch)
treee52935ce510440872ca5ce6b0e092cbc94f18bc9 /lib/bundler/environment_preserver.rb
parent68224651a4d4dc3ce0cea666f5423dd8b6ba6cfc (diff)
Update the bundler version with master branch
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3086
Diffstat (limited to 'lib/bundler/environment_preserver.rb')
-rw-r--r--lib/bundler/environment_preserver.rb28
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/bundler/environment_preserver.rb b/lib/bundler/environment_preserver.rb
index c9014badad..a77f7e0816 100644
--- a/lib/bundler/environment_preserver.rb
+++ b/lib/bundler/environment_preserver.rb
@@ -17,14 +17,38 @@ module Bundler
].map(&:freeze).freeze
BUNDLER_PREFIX = "BUNDLER_ORIG_".freeze
- # @param env [ENV]
+ def self.from_env
+ new(env_to_hash(ENV), BUNDLER_KEYS)
+ end
+
+ 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
+
+ # @param env [Hash]
# @param keys [Array<String>]
def initialize(env, keys)
- @original = env.to_hash
+ @original = env
@keys = keys
@prefix = BUNDLER_PREFIX
end
+ # Replaces `ENV` with the bundler environment variables backed up
+ 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
+
# @return [Hash]
def backup
env = @original.clone