Switch from module_function to eigenclass

This commit is contained in:
Douglas Eichelberger 2023-04-26 09:10:30 -07:00
parent 8f97dea167
commit 7229d03133

View File

@ -6,63 +6,63 @@ module Utils
# #
# @private # @private
module Autoremove module Autoremove
module_function class << self
# An array of all installed {Formula} with {Cask} dependents.
# @private
def formulae_with_cask_dependents(casks)
casks.flat_map { |cask| cask.depends_on[:formula] }
.compact
.map { |f| Formula[f] }
.flat_map { |f| [f, *f.runtime_formula_dependencies].compact }
end
private_class_method :formulae_with_cask_dependents
# An array of all installed {Formula} with {Cask} dependents. # An array of all installed {Formula} without runtime {Formula}
# @private # dependents for bottles and without build {Formula} dependents
def formulae_with_cask_dependents(casks) # for those built from source.
casks.flat_map { |cask| cask.depends_on[:formula] } # @private
.compact def formulae_with_no_formula_dependents(formulae)
.map { |f| Formula[f] } dependents = T.let([], T::Array[Formula])
.flat_map { |f| [f, *f.runtime_formula_dependencies].compact } formulae.each do |formula|
end dependents += formula.runtime_formula_dependencies
private_class_method :formulae_with_cask_dependents
# An array of all installed {Formula} without runtime {Formula} # Ignore build dependencies when the formula is a bottle
# dependents for bottles and without build {Formula} dependents next if Tab.for_keg(formula.any_installed_keg).poured_from_bottle
# for those built from source.
# @private
def formulae_with_no_formula_dependents(formulae)
dependents = T.let([], T::Array[Formula])
formulae.each do |formula|
dependents += formula.runtime_formula_dependencies
# Ignore build dependencies when the formula is a bottle formula.deps.select(&:build?).each do |dep|
next if Tab.for_keg(formula.any_installed_keg).poured_from_bottle dependents << dep.to_formula
rescue FormulaUnavailableError
formula.deps.select(&:build?).each do |dep| # do nothing
dependents << dep.to_formula end
rescue FormulaUnavailableError
# do nothing
end end
formulae - dependents
end end
formulae - dependents private_class_method :formulae_with_no_formula_dependents
end
private_class_method :formulae_with_no_formula_dependents
# Recursive function that returns an array of {Formula} without # Recursive function that returns an array of {Formula} without
# {Formula} dependents that weren't installed on request. # {Formula} dependents that weren't installed on request.
# @private # @private
def unused_formulae_with_no_formula_dependents(formulae) def unused_formulae_with_no_formula_dependents(formulae)
unused_formulae = formulae_with_no_formula_dependents(formulae).reject do |f| unused_formulae = formulae_with_no_formula_dependents(formulae).reject do |f|
Tab.for_keg(f.any_installed_keg).installed_on_request Tab.for_keg(f.any_installed_keg).installed_on_request
end
unless unused_formulae.empty?
unused_formulae += unused_formulae_with_no_formula_dependents(formulae - unused_formulae)
end
unused_formulae
end end
private_class_method :unused_formulae_with_no_formula_dependents
unless unused_formulae.empty? # An array of {Formula} without {Formula} or {Cask}
unused_formulae += unused_formulae_with_no_formula_dependents(formulae - unused_formulae) # dependents that weren't installed on request and without
# build dependencies for {Formula} installed from source.
# @private
def removable_formulae(formulae, casks)
unused_formulae = unused_formulae_with_no_formula_dependents(formulae)
unused_formulae - formulae_with_cask_dependents(casks)
end end
unused_formulae
end
private_class_method :unused_formulae_with_no_formula_dependents
# An array of {Formula} without {Formula} or {Cask}
# dependents that weren't installed on request and without
# build dependencies for {Formula} installed from source.
# @private
def removable_formulae(formulae, casks)
unused_formulae = unused_formulae_with_no_formula_dependents(formulae)
unused_formulae - formulae_with_cask_dependents(casks)
end end
end end
end end