Skip to content

Commit

Permalink
[rubygems/rubygems] Allow "default_user_install" to be overridden.
Browse files Browse the repository at this point in the history
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.

rubygems/rubygems@2320dba544
  • Loading branch information
voxik authored and hsbt committed Dec 14, 2023
1 parent 45b5114 commit 6126169
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 12 additions & 0 deletions lib/rubygems/defaults.rb
Expand Up @@ -235,6 +235,18 @@ def self.default_cert_path
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.

Expand Down
5 changes: 1 addition & 4 deletions lib/rubygems/installer.rb
Expand Up @@ -684,10 +684,7 @@ def process_options # :nodoc:
# * `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
Expand Down

0 comments on commit 6126169

Please sign in to comment.