Make Bundle::BrewDumper more Homebrew-y

- https://github.com/Homebrew/brew/pull/20182#discussion_r2170422499
This commit is contained in:
Issy Long 2025-06-27 18:15:37 +01:00
parent 0d40f48e8d
commit a2e39c4814
No known key found for this signature in database
2 changed files with 10 additions and 20 deletions

View File

@ -8,9 +8,7 @@ module Homebrew
module Bundle module Bundle
# TODO: refactor into multiple modules # TODO: refactor into multiple modules
module BrewDumper module BrewDumper
module_function def self.reset!
def reset!
require "bundle/brew_services" require "bundle/brew_services"
Homebrew::Bundle::BrewServices.reset! Homebrew::Bundle::BrewServices.reset!
@ -21,14 +19,14 @@ module Homebrew
@formula_oldnames = nil @formula_oldnames = nil
end end
def formulae def self.formulae
return @formulae if @formulae return @formulae if @formulae
formulae_by_full_name formulae_by_full_name
@formulae @formulae
end end
def formulae_by_full_name(name = nil) def self.formulae_by_full_name(name = nil)
return @formulae_by_full_name[name] if name.present? && @formulae_by_full_name&.key?(name) return @formulae_by_full_name[name] if name.present? && @formulae_by_full_name&.key?(name)
require "formula" require "formula"
@ -51,11 +49,11 @@ module Homebrew
{} {}
end end
def formulae_by_name(name) def self.formulae_by_name(name)
formulae_by_full_name(name) || @formulae_by_name[name] formulae_by_full_name(name) || @formulae_by_name[name]
end end
def dump(describe: false, no_restart: false) def self.dump(describe: false, no_restart: false)
require "bundle/brew_services" require "bundle/brew_services"
requested_formula = formulae.select do |f| requested_formula = formulae.select do |f|
@ -77,7 +75,7 @@ module Homebrew
end.join("\n") end.join("\n")
end end
def formula_aliases def self.formula_aliases
return @formula_aliases if @formula_aliases return @formula_aliases if @formula_aliases
@formula_aliases = {} @formula_aliases = {}
@ -96,7 +94,7 @@ module Homebrew
@formula_aliases @formula_aliases
end end
def formula_oldnames def self.formula_oldnames
return @formula_oldnames if @formula_oldnames return @formula_oldnames if @formula_oldnames
@formula_oldnames = {} @formula_oldnames = {}
@ -115,7 +113,7 @@ module Homebrew
@formula_oldnames @formula_oldnames
end end
def add_formula(formula) private_class_method def self.add_formula(formula)
hash = formula_to_hash formula hash = formula_to_hash formula
@formulae_by_name[hash[:name]] = hash @formulae_by_name[hash[:name]] = hash
@ -123,9 +121,8 @@ module Homebrew
hash hash
end end
private_class_method :add_formula
def formula_to_hash(formula) private_class_method def self.formula_to_hash(formula)
keg = if formula.linked? keg = if formula.linked?
link = true if formula.keg_only? link = true if formula.keg_only?
formula.linked_keg formula.linked_keg
@ -185,7 +182,6 @@ module Homebrew
official_tap: formula.tap&.official? || false, official_tap: formula.tap&.official? || false,
} }
end end
private_class_method :formula_to_hash
class Topo < Hash class Topo < Hash
include TSort include TSort
@ -200,7 +196,7 @@ module Homebrew
end end
end end
def sort!(formulae) private_class_method def self.sort!(formulae)
# Step 1: Sort by formula full name while putting tap formulae behind core formulae. # Step 1: Sort by formula full name while putting tap formulae behind core formulae.
# So we can have a nicer output. # So we can have a nicer output.
formulae = formulae.sort do |a, b| formulae = formulae.sort do |a, b|
@ -243,7 +239,6 @@ module Homebrew
brew install #{cycle_first} #{cycle_last} brew install #{cycle_first} #{cycle_last}
EOS EOS
end end
private_class_method :sort!
end end
end end
end end

View File

@ -1,5 +0,0 @@
# typed: true
module Homebrew::Bundle::BrewDumper
include Kernel
end