Skip to content

Commit

Permalink
[rubygems/rubygems] Make code to find target update version easier to…
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez authored and matzbot committed May 28, 2022
1 parent e9c4e37 commit 6e3295e
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions lib/rubygems/commands/update_command.rb
Expand Up @@ -163,8 +163,7 @@ def highest_remote_name_tuple(spec) # :nodoc:
spec_tuples = fetch_remote_gems spec

highest_remote_gem = spec_tuples.max

highest_remote_gem ||= [Gem::NameTuple.null]
return unless highest_remote_gem

highest_remote_gem.first
end
Expand Down Expand Up @@ -210,30 +209,22 @@ def rubygems_target_version
version = options[:system]
update_latest = version == true

if update_latest
version = Gem::Version.new Gem::VERSION
requirement = Gem::Requirement.new ">= #{Gem::VERSION}"
else
unless update_latest
version = Gem::Version.new version
requirement = Gem::Requirement.new version

return version, requirement
end

version = Gem::Version.new Gem::VERSION
requirement = Gem::Requirement.new ">= #{Gem::VERSION}"

rubygems_update = Gem::Specification.new
rubygems_update.name = 'rubygems-update'
rubygems_update.version = version

hig = {
'rubygems-update' => rubygems_update,
}

gems_to_update = which_to_update hig, options[:args], :system
up_ver = gems_to_update.first.version

target = if update_latest
up_ver
else
version
end
highest_remote_tup = highest_remote_name_tuple(rubygems_update)
target = highest_remote_tup ? highest_remote_tup.version : version

return target, requirement
end
Expand Down Expand Up @@ -302,20 +293,17 @@ def update_rubygems_arguments # :nodoc:
args
end

def which_to_update(highest_installed_gems, gem_names, system = false)
def which_to_update(highest_installed_gems, gem_names)
result = []

highest_installed_gems.each do |l_name, l_spec|
next if not gem_names.empty? and
gem_names.none? {|name| name == l_spec.name }

highest_remote_tup = highest_remote_name_tuple l_spec
highest_remote_ver = highest_remote_tup.version
highest_installed_ver = l_spec.version
next unless highest_remote_tup

if system or (highest_installed_ver < highest_remote_ver)
result << Gem::NameTuple.new(l_spec.name, [highest_installed_ver, highest_remote_ver].max, highest_remote_tup.platform)
end
result << highest_remote_tup
end

result
Expand Down

0 comments on commit 6e3295e

Please sign in to comment.