mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Eliminate repeated work in Formulary.factory
Much of the name resolution done in Formula.canonical_name is repeated Formulary.factory. Here we eliminate the repeated work by duplicating the code from canonical_name. Later we will refactor it so that both methods can share the bulk of the logic.
This commit is contained in:
parent
2616127a28
commit
ca3688e33e
@ -165,25 +165,54 @@ class Formulary
|
|||||||
# * a formula URL
|
# * a formula URL
|
||||||
# * a local bottle reference
|
# * a local bottle reference
|
||||||
def self.factory ref
|
def self.factory ref
|
||||||
# If a URL is passed, download to the cache and install
|
loader_for(ref).get_formula
|
||||||
if ref =~ %r[(https?|ftp)://]
|
end
|
||||||
f = FromUrlLoader.new(ref)
|
|
||||||
elsif ref =~ Pathname::BOTTLE_EXTNAME_RX
|
def self.loader_for(ref)
|
||||||
f = BottleLoader.new(ref)
|
case ref
|
||||||
else
|
when %r[(https?|ftp)://]
|
||||||
name_or_path = Formula.canonical_name(ref)
|
return FromUrlLoader.new(ref)
|
||||||
if name_or_path =~ HOMEBREW_TAP_FORMULA_REGEX
|
when Pathname::BOTTLE_EXTNAME_RX
|
||||||
# name appears to be a tapped formula, so we don't munge it
|
return BottleLoader.new(ref)
|
||||||
# in order to provide a useful error message when require fails.
|
end
|
||||||
f = TapLoader.new(name_or_path)
|
|
||||||
elsif name_or_path.include?("/") || File.extname(name_or_path) == ".rb"
|
if ref =~ HOMEBREW_TAP_FORMULA_REGEX
|
||||||
# If name was a path or mapped to a cached formula
|
tap_name = "#$1-#$2".downcase
|
||||||
f = FromPathLoader.new(name_or_path)
|
tapd = Pathname.new("#{HOMEBREW_LIBRARY}/Taps/#{tap_name}")
|
||||||
|
|
||||||
|
if tapd.directory?
|
||||||
|
tapd.find_formula do |relative_pathname|
|
||||||
|
path = "#{tapd}/#{relative_pathname}"
|
||||||
|
if relative_pathname.stem.to_s == $3
|
||||||
|
return FromPathLoader.new(path)
|
||||||
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
f = StandardLoader.new(name_or_path)
|
return TapLoader.new(ref)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
f.get_formula
|
if ref.include?("/") || File.extname(ref) == ".rb"
|
||||||
|
return FromPathLoader.new(ref)
|
||||||
|
end
|
||||||
|
|
||||||
|
formula_with_that_name = Formula.path(ref)
|
||||||
|
if formula_with_that_name.file? and formula_with_that_name.readable?
|
||||||
|
return StandardLoader.new(ref)
|
||||||
|
end
|
||||||
|
|
||||||
|
# test if the name is a formula alias
|
||||||
|
possible_alias = Pathname.new("#{HOMEBREW_LIBRARY}/Aliases/#{ref}")
|
||||||
|
if possible_alias.file?
|
||||||
|
name = possible_alias.resolved_path.basename(".rb").to_s
|
||||||
|
return StandardLoader.new(name)
|
||||||
|
end
|
||||||
|
|
||||||
|
possible_cached_formula = Pathname.new("#{HOMEBREW_CACHE_FORMULA}/#{ref}.rb")
|
||||||
|
if possible_cached_formula.file?
|
||||||
|
return FromPathLoader.new(possible_cached_formula.to_s)
|
||||||
|
end
|
||||||
|
|
||||||
|
return StandardLoader.new(ref)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user