Merge pull request #15631 from MikeMcQuaid/remove_versioned_formula_files

Remove `Tap#versioned_formula_files`
This commit is contained in:
Mike McQuaid 2023-07-05 16:42:47 +01:00 committed by GitHub
commit a34d46e093
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 20 deletions

View File

@ -465,21 +465,19 @@ class Formula
# Returns any `@`-versioned formulae names for any formula (including versioned formulae).
sig { returns(T::Array[String]) }
def versioned_formulae_names
versioned_paths = if tap
# Faster path, due to `tap.versioned_formula_files` caching.
versioned_names = if tap
name_prefix = "#{name.gsub(/(@[\d.]+)?$/, "")}@"
tap.versioned_formula_files.select do |file|
file.basename.to_s.start_with?(name_prefix)
tap.formula_names.select do |name|
name.start_with?(name_prefix)
end
else
elsif path.exist?
Pathname.glob(path.to_s.gsub(/(@[\d.]+)?\.rb$/, "@*.rb"))
.map { |path| path.basename(".rb").to_s }
end.sort
versioned_names.reject do |versioned_name|
versioned_name == name
end
versioned_paths.map do |versioned_path|
next if versioned_path == path
versioned_path.basename(".rb").to_s
end.compact.sort
end
# Returns any `@`-versioned Formula objects for any Formula (including versioned formulae).

View File

@ -530,14 +530,6 @@ class Tap
end
end
# An array of all versioned {Formula} files of this {Tap}.
sig { returns(T::Array[Pathname]) }
def versioned_formula_files
@versioned_formula_files ||= formula_files.select do |file|
file.basename(".rb").to_s =~ /@[\d.]+$/
end
end
# An array of all {Cask} files of this {Tap}.
sig { returns(T::Array[Pathname]) }
def cask_files

View File

@ -156,7 +156,7 @@ describe Formula do
allow(Formulary).to receive(:load_formula_from_path).with(f2.name, f2.path).and_return(f2)
allow(Formulary).to receive(:factory).with(f2.name).and_return(f2)
allow(f.tap).to receive(:versioned_formula_files).and_return([f2.path])
allow(f).to receive(:versioned_formulae_names).and_return([f2.name])
end
it "returns array with versioned formulae" do