summaryrefslogtreecommitdiff
path: root/lib/rubygems/commands/update_command.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/commands/update_command.rb')
-rw-r--r--lib/rubygems/commands/update_command.rb62
1 files changed, 26 insertions, 36 deletions
diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb
index 7c24fedcde..8e80d46856 100644
--- a/lib/rubygems/commands/update_command.rb
+++ b/lib/rubygems/commands/update_command.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require_relative "../command"
require_relative "../command_manager"
require_relative "../dependency_installer"
@@ -20,7 +21,7 @@ class Gem::Commands::UpdateCommand < Gem::Command
def initialize
options = {
- :force => false,
+ force: false,
}
options.merge!(install_update_options)
@@ -36,10 +37,10 @@ class Gem::Commands::UpdateCommand < Gem::Command
end
add_option("--system [VERSION]", Gem::Version,
- "Update the RubyGems system software") do |value, options|
- value = true unless value
+ "Update the RubyGems system software") do |value, opts|
+ value ||= true
- options[:system] = value
+ opts[:system] = value
end
add_local_remote_options
@@ -119,7 +120,7 @@ command to remove old versions.
updated = update_gems gems_to_update
installed_names = highest_installed_gems.keys
- updated_names = updated.map {|spec| spec.name }
+ updated_names = updated.map(&:name)
not_updated_names = options[:args].uniq - updated_names
not_installed_names = not_updated_names - installed_names
up_to_date_names = not_updated_names - not_installed_names
@@ -127,10 +128,10 @@ command to remove old versions.
if updated.empty?
say "Nothing to update"
else
- say "Gems updated: #{updated_names.join(' ')}"
+ say "Gems updated: #{updated_names.join(" ")}"
end
- say "Gems already up-to-date: #{up_to_date_names.join(' ')}" unless up_to_date_names.empty?
- say "Gems not currently installed: #{not_installed_names.join(' ')}" unless not_installed_names.empty?
+ say "Gems already up-to-date: #{up_to_date_names.join(" ")}" unless up_to_date_names.empty?
+ say "Gems not currently installed: #{not_installed_names.join(" ")}" unless not_installed_names.empty?
end
def fetch_remote_gems(spec) # :nodoc:
@@ -185,7 +186,9 @@ command to remove old versions.
system Gem.ruby, "--disable-gems", "setup.rb", *args
end
- say "RubyGems system software updated" if installed unless options[:silent]
+ unless options[:silent]
+ say "RubyGems system software updated" if installed
+ end
end
end
@@ -194,18 +197,17 @@ command to remove old versions.
yield
else
require "tmpdir"
- tmpdir = Dir.mktmpdir
- FileUtils.mv Gem.plugindir, tmpdir
+ Dir.mktmpdir("gem_update") do |tmpdir|
+ FileUtils.mv Gem.plugindir, tmpdir
- status = yield
+ status = yield
- if status
- FileUtils.rm_rf tmpdir
- else
- FileUtils.mv File.join(tmpdir, "plugins"), Gem.plugindir
- end
+ unless status
+ FileUtils.mv File.join(tmpdir, "plugins"), Gem.plugindir
+ end
- status
+ status
+ end
end
end
@@ -230,7 +232,7 @@ command to remove old versions.
highest_remote_tup = highest_remote_name_tuple(rubygems_update)
target = highest_remote_tup ? highest_remote_tup.version : version
- return target, requirement
+ [target, requirement]
end
def update_gem(name, version = Gem::Requirement.default)
@@ -241,7 +243,7 @@ command to remove old versions.
@installer = Gem::DependencyInstaller.new update_options
- say "Updating #{name}" unless options[:system] && options[:silent]
+ say "Updating #{name}" unless options[:system]
begin
@installer.install name, Gem::Requirement.new(version)
rescue Gem::InstallError, Gem::DependencyError => e
@@ -279,7 +281,7 @@ command to remove old versions.
check_oldest_rubygems version
installed_gems = Gem::Specification.find_all_by_name "rubygems-update", requirement
- installed_gems = update_gem("rubygems-update", version) if installed_gems.empty? || installed_gems.first.version != version
+ installed_gems = update_gem("rubygems-update", requirement) if installed_gems.empty? || installed_gems.first.version != version
return if installed_gems.empty?
install_rubygems installed_gems.first
@@ -291,16 +293,14 @@ command to remove old versions.
args << "--prefix" << Gem.prefix if Gem.prefix
args << "--no-document" unless options[:document].include?("rdoc") || options[:document].include?("ri")
args << "--no-format-executable" if options[:no_format_executable]
- args << "--previous-version" << Gem::VERSION if
- options[:system] == true ||
- Gem::Version.new(options[:system]) >= Gem::Version.new(2)
+ args << "--previous-version" << Gem::VERSION
args
end
def which_to_update(highest_installed_gems, gem_names)
result = []
- highest_installed_gems.each do |l_name, l_spec|
+ highest_installed_gems.each do |_l_name, l_spec|
next if !gem_names.empty? &&
gem_names.none? {|name| name == l_spec.name }
@@ -325,18 +325,8 @@ command to remove old versions.
@oldest_supported_version ||=
if Gem.ruby_version > Gem::Version.new("3.1.a")
Gem::Version.new("3.3.3")
- elsif Gem.ruby_version > Gem::Version.new("3.0.a")
- Gem::Version.new("3.2.3")
- elsif Gem.ruby_version > Gem::Version.new("2.7.a")
- Gem::Version.new("3.1.2")
- elsif Gem.ruby_version > Gem::Version.new("2.6.a")
- Gem::Version.new("3.0.1")
- elsif Gem.ruby_version > Gem::Version.new("2.5.a")
- Gem::Version.new("2.7.3")
- elsif Gem.ruby_version > Gem::Version.new("2.4.a")
- Gem::Version.new("2.6.8")
else
- Gem::Version.new("2.5.2")
+ Gem::Version.new("3.2.3")
end
end
end