[rubygems/rubygems] Factor group-filtering to a private method to reduce repetition

We're about to expand the repeated bit of code, so drying it up a little
is warranted.

e69c658be6
This commit is contained in:
Eric Mueller 2023-11-15 19:45:39 -08:00 committed by git
parent 11d7c75fb3
commit a54c98a29f

View file

@ -102,24 +102,17 @@ module Bundler
Bundler.ui.info(nothing_outdated_message) Bundler.ui.info(nothing_outdated_message)
end end
else else
if options_include_groups relevant_outdated_gems = if options_include_groups
relevant_outdated_gems = outdated_gems.group_by {|g| g[:groups] }.sort.flat_map do |groups, gems| by_group(outdated_gems, :filter => options[:group])
contains_group = groups.split(", ").include?(options[:group]) else
next unless options[:groups] || contains_group outdated_gems
end
gems
end.compact
if options[:parseable] if options[:parseable]
print_gems(relevant_outdated_gems) print_gems(relevant_outdated_gems)
else else
print_gems_table(relevant_outdated_gems) print_gems_table(relevant_outdated_gems)
end end
elsif options[:parseable]
print_gems(outdated_gems)
else
print_gems_table(outdated_gems)
end
exit 1 exit 1
end end
@ -162,6 +155,13 @@ module Bundler
active_specs.last active_specs.last
end end
def by_group(gems, filter: nil)
gems.group_by {|g| g[:groups] }.sort.flat_map do |groups_string, grouped_gems|
next if filter && !groups_string.split(", ").include?(filter)
grouped_gems
end.compact
end
def print_gems(gems_list) def print_gems(gems_list)
gems_list.each do |gem| gems_list.each do |gem|
print_gem( print_gem(