summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-01-30 20:06:09 -0600
committerAndre Arko <andre@arko.net>2016-01-31 14:05:00 -0800
commit3c94eb747cf461ff334ce57bf72638d5aee29afa (patch)
tree39e1c47837775bb3fb2e4b61e70e714424b52940
parentd713762416079b862d287b5806c4e6f5e7b4146c (diff)
downloadbundler-3c94eb747cf461ff334ce57bf72638d5aee29afa.tar.gz
Refactor path preservation into generic code
-rw-r--r--lib/bundler.rb6
-rw-r--r--lib/bundler/gem_path_manipulation.rb15
-rw-r--r--lib/bundler/path_preserver.rb11
3 files changed, 14 insertions, 18 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index d6af64052e..474253aabd 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -2,7 +2,7 @@ require "fileutils"
require "pathname"
require "rbconfig"
require "thread"
-require "bundler/gem_path_manipulation"
+require "bundler/path_preserver"
require "bundler/gem_remote_fetcher"
require "bundler/rubygems_ext"
require "bundler/rubygems_integration"
@@ -12,8 +12,8 @@ require "bundler/current_ruby"
require "bundler/errors"
module Bundler
- preserve_gem_path
- preserve_path
+ PathPreserver.preserve_path_in_environment("PATH", ENV)
+ PathPreserver.preserve_path_in_environment("GEM_PATH", ENV)
ORIGINAL_ENV = ENV.to_hash
SUDO_MUTEX = Mutex.new
diff --git a/lib/bundler/gem_path_manipulation.rb b/lib/bundler/gem_path_manipulation.rb
deleted file mode 100644
index 3a89b91e50..0000000000
--- a/lib/bundler/gem_path_manipulation.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-module Bundler
- def self.preserve_gem_path
- original_gem_path = ENV["_ORIGINAL_GEM_PATH"]
- gem_path = ENV["GEM_PATH"]
- ENV["_ORIGINAL_GEM_PATH"] = gem_path if original_gem_path.nil? || original_gem_path == ""
- ENV["GEM_PATH"] = original_gem_path if gem_path.nil? || gem_path == ""
- end
-
- def self.preserve_path
- original_path = ENV["_ORIGINAL_PATH"]
- path = ENV["PATH"]
- ENV["_ORIGINAL_PATH"] = path if original_path.nil? || original_path == ""
- ENV["PATH"] = original_path if path.nil? || path == ""
- end
-end
diff --git a/lib/bundler/path_preserver.rb b/lib/bundler/path_preserver.rb
new file mode 100644
index 0000000000..8d83cd9077
--- /dev/null
+++ b/lib/bundler/path_preserver.rb
@@ -0,0 +1,11 @@
+module Bundler
+ module PathPreserver
+ def self.preserve_path_in_environment(env_var, env = ENV)
+ original_env_var = "_ORIGINAL_#{env_var}"
+ original_path = ENV[original_env_var]
+ path = ENV[env_var]
+ ENV[original_env_var] = path if original_path.nil? || original_path.empty?
+ ENV[env_var] = original_path if path.nil? || path.empty?
+ end
+ end
+end