Skip to content

Commit 2320dba

Browse files
voxikmartinemde
authored andcommitted
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.
1 parent 36c675c commit 2320dba

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/rubygems/defaults.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,18 @@ def self.default_cert_path
235235
default_cert_path
236236
end
237237

238+
##
239+
# Enables automatic installation into user directory
240+
241+
def self.default_user_install # :nodoc:
242+
if !ENV.key?("GEM_HOME") && (File.exist?(Gem.dir) && !File.writable?(Gem.dir))
243+
Gem.ui.say "Defaulting to user installation because default installation directory (#{Gem.dir}) is not writable."
244+
return true
245+
end
246+
247+
false
248+
end
249+
238250
##
239251
# Install extensions into lib as well as into the extension directory.
240252

lib/rubygems/installer.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,7 @@ def process_options # :nodoc:
684684
# * `true`: `--user-install`
685685
# * `false`: `--no-user-install` and
686686
# * `nil`: option was not specified
687-
if options[:user_install]
688-
@gem_home = Gem.user_dir
689-
elsif options[:user_install].nil? && !ENV.key?("GEM_HOME") && (File.exist?(Gem.dir) && !File.writable?(Gem.dir))
690-
say "Defaulting to user installation because default installation directory (#{Gem.dir}) is not writable."
687+
if options[:user_install] || (options[:user_install].nil? && Gem.default_user_install)
691688
@gem_home = Gem.user_dir
692689
end
693690
end

0 commit comments

Comments
 (0)