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 | |
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')
-rw-r--r-- | lib/bundler.rb | 21 | ||||
-rw-r--r-- | lib/bundler/plugin.rb | 6 | ||||
-rw-r--r-- | lib/bundler/settings.rb | 2 |
3 files changed, 23 insertions, 6 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 diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb index 99c9a867b0..7db159c593 100644 --- a/lib/bundler/plugin.rb +++ b/lib/bundler/plugin.rb @@ -80,8 +80,8 @@ module Bundler # The directory root for all plugin related data # - # Points to root in app_config_path if ran in an app else points to the one - # in user_bundle_path + # If run in an app, points to local root, in app_config_path + # Otherwise, points to global root, in Bundler.user_bundle_path("plugin") def root @root ||= if SharedHelpers.in_bundle? local_root @@ -96,7 +96,7 @@ module Bundler # The global directory root for all plugin related data def global_root - Bundler.user_bundle_path.join("plugin") + Bundler.user_bundle_path("plugin") end # The cache directory for plugin stuffs diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index c58eb3d494..c2fe71be2b 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -392,7 +392,7 @@ module Bundler Pathname.new(ENV["BUNDLE_CONFIG"]) else begin - Bundler.user_bundle_path.join("config") + Bundler.user_bundle_path("config") rescue PermissionError, GenericSystemCallError nil end |