Merge pull request #13755 from Bo98/versioned_formulae_names-optimise
formula: try optimise `versioned_formulae_names`
This commit is contained in:
commit
b2ddb341a0
@ -447,7 +447,17 @@ class Formula
|
|||||||
# Returns any `@`-versioned formulae names for any formula (including versioned formulae).
|
# Returns any `@`-versioned formulae names for any formula (including versioned formulae).
|
||||||
sig { returns(T::Array[String]) }
|
sig { returns(T::Array[String]) }
|
||||||
def versioned_formulae_names
|
def versioned_formulae_names
|
||||||
Pathname.glob(path.to_s.gsub(/(@[\d.]+)?\.rb$/, "@*.rb")).map do |versioned_path|
|
versioned_paths = if tap
|
||||||
|
# Faster path, due to `tap.versioned_formula_files` caching.
|
||||||
|
name_prefix = "#{name.gsub(/(@[\d.]+)?$/, "")}@"
|
||||||
|
tap.versioned_formula_files.select do |file|
|
||||||
|
file.basename.to_s.start_with?(name_prefix)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Pathname.glob(path.to_s.gsub(/(@[\d.]+)?\.rb$/, "@*.rb"))
|
||||||
|
end
|
||||||
|
|
||||||
|
versioned_paths.map do |versioned_path|
|
||||||
next if versioned_path == path
|
next if versioned_path == path
|
||||||
|
|
||||||
versioned_path.basename(".rb").to_s
|
versioned_path.basename(".rb").to_s
|
||||||
|
|||||||
@ -491,6 +491,13 @@ class Tap
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# An array of all versioned {Formula} files of this {Tap}.
|
||||||
|
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}.
|
# An array of all {Cask} files of this {Tap}.
|
||||||
def cask_files
|
def cask_files
|
||||||
@cask_files ||= if cask_dir.directory?
|
@cask_files ||= if cask_dir.directory?
|
||||||
|
|||||||
@ -149,11 +149,15 @@ describe Formula do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
before 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])
|
||||||
|
end
|
||||||
|
|
||||||
it "returns array with versioned formulae" do
|
it "returns array with versioned formulae" do
|
||||||
FileUtils.touch f.path
|
FileUtils.touch f.path
|
||||||
FileUtils.touch f2.path
|
FileUtils.touch f2.path
|
||||||
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)
|
|
||||||
expect(f.versioned_formulae).to eq [f2]
|
expect(f.versioned_formulae).to eq [f2]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user