aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/utils.rb
diff options
context:
space:
mode:
authorMike McQuaid2017-10-29 14:44:43 +0000
committerMike McQuaid2017-10-29 14:44:43 +0000
commitca189437e4d35f9e6c89f4b7955613f708ab3282 (patch)
treed91421a865326f2c15313a621d7a38908d735a2b /Library/Homebrew/utils.rb
parent7caca570736a6232512328992b398270dbbf3f4f (diff)
downloadbrew-ca189437e4d35f9e6c89f4b7955613f708ab3282.tar.bz2
Tweak use of with_env
- Use it in more places where it saves code - Allow using symbolic keys for a cleaner interface - Use `HOMEBREW_GEM_*` instead of `GEM_OLD_*`
Diffstat (limited to 'Library/Homebrew/utils.rb')
-rw-r--r--Library/Homebrew/utils.rb37
1 files changed, 17 insertions, 20 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index 2211ed75b..0c875a8ab 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -189,9 +189,11 @@ module Homebrew
def install_gem_setup_path!(name, version = nil, executable = name)
# Respect user's preferences for where gems should be installed.
- ENV["GEM_HOME"] = ENV["GEM_OLD_HOME"].to_s
+ ENV["GEM_HOME"] = ENV["HOMEBREW_GEM_HOME"].to_s
ENV["GEM_HOME"] = Gem.user_dir if ENV["GEM_HOME"].empty?
- ENV["GEM_PATH"] = ENV["GEM_OLD_PATH"] unless ENV["GEM_OLD_PATH"].to_s.empty?
+ unless ENV["HOMEBREW_GEM_PATH"].to_s.empty?
+ ENV["GEM_PATH"] = ENV["HOMEBREW_GEM_PATH"]
+ end
# Make rubygems notice env changes.
Gem.clear_paths
@@ -263,31 +265,25 @@ module Homebrew
end
def with_system_path
- old_path = ENV["PATH"]
- ENV["PATH"] = PATH.new("/usr/bin", "/bin")
- yield
-ensure
- ENV["PATH"] = old_path
+ with_env(PATH: PATH.new("/usr/bin", "/bin")) do
+ yield
+ end
end
def with_homebrew_path
- old_path = ENV["PATH"]
- ENV["PATH"] = ENV["HOMEBREW_PATH"]
- yield
-ensure
- ENV["PATH"] = old_path
+ with_env(PATH: PATH.new(ENV["HOMEBREW_PATH"])) do
+ yield
+ end
end
def with_custom_locale(locale)
- old_locale = ENV["LC_ALL"]
- ENV["LC_ALL"] = locale
- yield
-ensure
- ENV["LC_ALL"] = old_locale
+ with_env(LC_ALL: locale) do
+ yield
+ end
end
-def run_as_not_developer(&_block)
- with_env "HOMEBREW_DEVELOPER" => nil do
+def run_as_not_developer
+ with_env(HOMEBREW_DEVELOPER: nil) do
yield
end
end
@@ -536,7 +532,7 @@ end
# Calls the given block with the passed environment variables
# added to ENV, then restores ENV afterwards.
# Example:
-# with_env "PATH" => "/bin" do
+# with_env(PATH: "/bin") do
# system "echo $PATH"
# end
#
@@ -547,6 +543,7 @@ def with_env(hash)
old_values = {}
begin
hash.each do |key, value|
+ key = key.to_s
old_values[key] = ENV.delete(key)
ENV[key] = value
end