lib/right_develop/utility/shell.rb in right_develop-2.2.4 vs lib/right_develop/utility/shell.rb in right_develop-2.3.0

- old
+ new

@@ -45,23 +45,26 @@ # won't clean them. also, if you 'bundle exec rake ...' and then put # arguments to the right of the task name, then these args won't appear in # Bundler::ORIGINAL_ENV. # example: "bundle exec rake build:all DEBUG=true ..." def setup_clean_env - # a little revisionist history music... - ::ENV.each do |key, value| - if key.start_with?('GEM_') || key.start_with?('BUNDLER_') - ::Bundler::ORIGINAL_ENV[key] = nil - elsif Bundler::ORIGINAL_ENV[key].nil? - ::Bundler::ORIGINAL_ENV[key] = value + # user may be running gem binary directly without bundler. + if defined?(::Bundler) + # a little revisionist history music... + ::ENV.each do |key, value| + if key.start_with?('GEM_') || key.start_with?('BUNDLER_') + ::Bundler::ORIGINAL_ENV[key] = nil + elsif Bundler::ORIGINAL_ENV[key].nil? + ::Bundler::ORIGINAL_ENV[key] = value + end end + ::Bundler.with_clean_env do + # now the ENV is clean and not missing any right-hand args so replace + # the ORIGINAL_ENV. + ::Bundler::ORIGINAL_ENV.replace(ENV) + end end - ::Bundler.with_clean_env do - # now the ENV is clean and not missing any right-hand args so replace - # the ORIGINAL_ENV. - ::Bundler::ORIGINAL_ENV.replace(ENV) - end true end # @return [TrueClass|FalseClass] true if running on Windows platform def is_windows? @@ -116,10 +119,26 @@ # super configure early to ensure that any custom env vars are set after # restoring the pre-bundler env. executioner = super(executioner, options) # clean all bundler env vars, if requested. - if options[:clean_bundler_env] && defined?(::Bundler) + if options[:clean_bundler_env] + executioner = wrap_executioner_with_clean_env(executioner) + end + executioner + end + + # Encapsulates executioner with bundler-defeating logic, but only if + # bundler has been loaded by current process. + # + # @param [Proc] executioner to conditionally wrap + # + # @return [Proc] wrapped or original executioner + def wrap_executioner_with_clean_env(executioner) + # only if bundler is loaded. + if defined?(::Bundler) + # double-lambda, single call freezes the inner call made to previous + # definition of executioner. executioner = lambda do |e| lambda { ::Bundler.with_clean_env { e.call } } end.call(executioner) end executioner