[rubygems/rubygems] Allow "default_user_install" to be overridden.

For Ruby re-distributors, automatic user-install might be the right
default. Therefore printing warning about installing into user directory
is not always desirable. Let the default_user_install method be
customizable.

https://github.com/rubygems/rubygems/commit/2320dba544
This commit is contained in:
Vít Ondruch 2023-12-08 16:38:51 +01:00 committed by Hiroshi SHIBATA
parent 45b511433d
commit 612616925b
No known key found for this signature in database
GPG Key ID: F9CF13417264FAC2
2 changed files with 13 additions and 4 deletions

View File

@ -235,6 +235,18 @@ module Gem
default_cert_path
end
##
# Enables automatic installation into user directory
def self.default_user_install # :nodoc:
if !ENV.key?("GEM_HOME") && (File.exist?(Gem.dir) && !File.writable?(Gem.dir))
Gem.ui.say "Defaulting to user installation because default installation directory (#{Gem.dir}) is not writable."
return true
end
false
end
##
# Install extensions into lib as well as into the extension directory.

View File

@ -684,10 +684,7 @@ class Gem::Installer
# * `true`: `--user-install`
# * `false`: `--no-user-install` and
# * `nil`: option was not specified
if options[:user_install]
@gem_home = Gem.user_dir
elsif options[:user_install].nil? && !ENV.key?("GEM_HOME") && (File.exist?(Gem.dir) && !File.writable?(Gem.dir))
say "Defaulting to user installation because default installation directory (#{Gem.dir}) is not writable."
if options[:user_install] || (options[:user_install].nil? && Gem.default_user_install)
@gem_home = Gem.user_dir
end
end