From 48eb732d710b772d99ea5932b3b05716b61a3535 Mon Sep 17 00:00:00 2001 From: Fumihito Hachinohe Date: Mon, 2 Aug 2021 00:09:53 +0900 Subject: [PATCH] use `Bundler.with_unbundled_env` instead of `Bundler.with_clean_env` This fixes the following warning: ``` [DEPRECATED] Bundler.with_clean_env has been deprecated in favor of Bundler.with_unbundled_env. If you instead want the environment before bundler was originally loaded, use Bundler.with_original_env (called at /app/.bundle/vendor/ruby/3.0.0/gems/capistrano-locally-0.2.7/lib/capistrano/locally.rb:26) ``` Signed-off-by: Fumihito Hachinohe --- README.md | 5 +++-- lib/capistrano/locally.rb | 25 +++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1272000..4caa68b 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,10 @@ Require in `Capfile`: server 'localhost', roles: %w{app web} # no need to set SSH configs. ### Options -**`:run_locally_with_clean_env`** (default: `true`) +**`:run_locally_with_unbundled_env`** (default: `true`) -When using bundler, commands are executed in `Bundler.with_clean_env` by default so as not to affect the executable ruby scripts. To explicitly inherit environment variables, set this `false`. +Previous name is **`run_locally_with_clean_env`**. +When using bundler, commands are executed in `Bundler.with_unbundled_env` by default so as not to affect the executable ruby scripts. To explicitly inherit environment variables, set this `false`. ## Development diff --git a/lib/capistrano/locally.rb b/lib/capistrano/locally.rb index 6820548..13cca23 100644 --- a/lib/capistrano/locally.rb +++ b/lib/capistrano/locally.rb @@ -22,8 +22,9 @@ def on(hosts, options={}, &block) else SSHKit::Backend::Local end - if (defined? Bundler) && fetch(:run_locally_with_clean_env, true) - Bundler.with_clean_env do + + if (defined? Bundler) && fetch_setting_related_bundler_with_unbundled_env + Bundler.with_unbundled_env do klass.new(localhost, &block).run end else @@ -39,5 +40,25 @@ def on(hosts, options={}, &block) def dry_run? fetch(:sshkit_backend) == SSHKit::Backend::Printer end + + def fetch_setting_related_bundler_with_unbundled_env + value = fetch(:run_locally_with_unbundled_env) + value = fetch_run_locally_with_clean_env if use.nil? + value = true if use.nil? + + value + end + + def fetch_run_locally_with_clean_env + value = fetch(:run_locally_with_clean_env) + + unless value.nil? + $stderr.puts(<<-MESSAGE) +[Deprecation Notice] `set :run_locally_with_clean_env` has been deprecated in favor of `set :run_locally_with_unbundled_env`. +MESSAGE + end + + value + end end end