Change to pluralize, port more call sites

This commit is contained in:
Douglas Eichelberger 2023-02-23 12:14:37 -08:00
parent 0438a3a538
commit 37015b6b08
7 changed files with 14 additions and 14 deletions

View File

@ -85,7 +85,7 @@ module Cask
if dry_run
if (casks_to_install = casks.reject(&:installed?).presence)
plural = ::Utils::Inflection.number(casks_to_install.count, "cask")
plural = ::Utils::Inflection.pluralize("cask", casks_to_install.count)
ohai "Would install #{casks_to_install.count} #{plural}:"
puts casks_to_install.map(&:full_name).join(" ")
end
@ -97,7 +97,7 @@ module Cask
.map(&:name)
next if dep_names.blank?
plural = ::Utils::Inflection.number(dep_names.count, "dependenc", "ies", "y")
plural = ::Utils::Inflection.pluralize("dependenc", dep_names.count, plural: "ies", singular: "y")
ohai "Would install #{dep_names.count} #{plural} for #{cask.full_name}:"
puts dep_names.join(" ")
end

View File

@ -46,7 +46,7 @@ module Cask
next if (versions = cask.versions).empty?
puts <<~EOS
#{cask} #{versions.to_sentence} #{::Utils::Inflection.number(versions.count, "", "are", "is")} still installed.
#{cask} #{versions.to_sentence} #{::Utils::Inflection.pluralize("", versions.count, plural: "are", singular: "is")} still installed.
Remove #{(versions.count == 1) ? "it" : "them all"} with `brew uninstall --cask --force #{cask}`.
EOS
end

View File

@ -121,7 +121,7 @@ module Cask
if manual_installer_casks.present?
count = manual_installer_casks.count
ofail "Not upgrading #{count} `installer manual` #{::Utils::Inflection.number(versions.count, "cask")}."
ofail "Not upgrading #{count} `installer manual` #{::Utils::Inflection.pluralize("cask", versions.count)}."
puts manual_installer_casks.map(&:to_s)
outdated_casks -= manual_installer_casks
end
@ -142,7 +142,7 @@ module Cask
end
verb = dry_run ? "Would upgrade" : "Upgrading"
oh1 "#{verb} #{outdated_casks.count} outdated #{::Utils::Inflection.number(outdated_casks.count, "package")}:"
oh1 "#{verb} #{outdated_casks.count} outdated #{::Utils::Inflection.pluralize("package", outdated_casks.count)}:"
caught_exceptions = []

View File

@ -584,7 +584,7 @@ module Homebrew
formulae_names = removable_formulae.map(&:full_name).sort
verb = dry_run ? "Would autoremove" : "Autoremoving"
oh1 "#{verb} #{formulae_names.count} unneeded #{"formula".pluralize(formulae_names.count)}:"
oh1 "#{verb} #{formulae_names.count} unneeded #{Utils::Inflection.pluralize("formula", formulae_names.count, plural: "e")}:"
puts formulae_names.join("\n")
return if dry_run

View File

@ -684,7 +684,7 @@ module Homebrew
arg_types = types.map { |type| type.to_s.tr("_", " ") }
.to_sentence two_words_connector: " or ", last_word_connector: " or "
"This command does not take more than #{maximum} #{arg_types} #{"argument".pluralize(maximum)}."
"This command does not take more than #{maximum} #{arg_types} #{Utils::Inflection.pluralize("argument", maximum)}."
end
end
end
@ -698,7 +698,7 @@ module Homebrew
arg_types = types.map { |type| type.to_s.tr("_", " ") }
.to_sentence two_words_connector: " or ", last_word_connector: " or "
super "This command requires at least #{minimum} #{arg_types} #{"argument".pluralize(minimum)}."
super "This command requires at least #{minimum} #{arg_types} #{Utils::Inflection.pluralize("argument", minimum)}."
end
end
@ -711,7 +711,7 @@ module Homebrew
arg_types = types.map { |type| type.to_s.tr("_", " ") }
.to_sentence two_words_connector: " or ", last_word_connector: " or "
super "This command requires exactly #{minimum} #{arg_types} #{"argument".pluralize(minimum)}."
super "This command requires exactly #{minimum} #{arg_types} #{Utils::Inflection.pluralize("argument", minimum)}."
end
end
end

View File

@ -906,11 +906,11 @@ module Homebrew
0
end
"#{tap.path} (#{cask_count} #{"cask".pluralize(cask_count)})"
"#{tap.path} (#{cask_count} #{Utils::Inflection.pluralize("cask", cask_count)})"
end
end)
taps = "tap".pluralize error_tap_paths.count
taps = Utils::Inflection.pluralize("tap", error_tap_paths.count)
"Unable to read from cask #{taps}: #{error_tap_paths.to_sentence}" if error_tap_paths.present?
end

View File

@ -8,9 +8,9 @@ module Utils
module Inflection
extend T::Sig
# Combines `stem`` with the `singular`` or `plural` suffix based on `count`.
sig { params(count: Integer, stem: String, plural: String, singular: String).returns(String) }
def self.number(count, stem, plural = "s", singular = "")
# Combines `stem` with the `singular` or `plural` suffix based on `count`.
sig { params(stem: String, count: Integer, plural: String, singular: String).returns(String) }
def self.pluralize(stem, count, plural: "s", singular: "")
suffix = (count == 1) ? singular : plural
"#{stem}#{suffix}"
end