diff options
author | Greg Werbin <spam@me.gregwerbin.com> | 2017-09-10 20:30:43 -0400 |
---|---|---|
committer | Greg Werbin <spam@me.gregwerbin.com> | 2017-09-10 20:49:25 -0400 |
commit | b241c53d1782745d694545000a7f4c251b243a1b (patch) | |
tree | f7008c29ae5d544979edfe248c7e9458c559eef0 /lib/bundler.rb | |
parent | 4897ee981aabff9b5483edbd42c1be7616183707 (diff) | |
download | bundler-b241c53d1782745d694545000a7f4c251b243a1b.tar.gz |
Allow the user to set alternative to ~/.bundle
Recognize new environment variables, with the following fallbacks:
$BUNDLE_USER_HOME -> $HOME/.bundle
$BUNDLE_USER_CACHE -> $BUNDLE_USER_HOME/cache
$BUNDLE_USER_CONFIG -> $BUNDLE_USER_HOME/config
$BUNDLE_USER_PLUGIN -> $BUNDLE_USER_HOME/plugin
TODOs:
- Error handling in Bundler.user_bundle_path when an invalid option is
passed
- Add tests (see https://github.com/bundler/bundler/pull/5787/commits/47fbe99387fea73fa652ad6692349b24cad6fe2e)
- Draft PR with reference to GitHub issue numbers (not linked here as
per contributing guidelines)
+ Issue: 4333
+ Pull request: 5787
Diffstat (limited to 'lib/bundler.rb')
-rw-r--r-- | lib/bundler.rb | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 81c6a5b594..31602dfa65 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -193,10 +193,27 @@ module Bundler raise e.exception("#{warning}\nBundler also failed to create a temporary home directory at `#{path}':\n#{e}") end - def user_bundle_path + def user_bundle_path_default Pathname.new(user_home).join(".bundle") end + def user_bundle_path(dir="home") + # if "home", user_bundle_path_default + env_var, fallback = case dir + when "home" + ["BUNDLE_USER_HOME", user_bundle_path_default] + when "cache" + ["BUNDLE_USER_CACHE", user_bundle_path.join("cache")] + when "config" + ["BUNDLE_USER_CONFIG", user_bundle_path.join("config")] + when "plugin" + ["BUNDLE_USER_PLUGIN", user_bundle_path.join("plugin")] + else + nil + end + ENV.fetch(env_var, fallback) + end + def home bundle_path.join("bundler") end @@ -210,7 +227,7 @@ module Bundler end def user_cache - user_bundle_path.join("cache") + user_bundle_path("cache") end def root |