Implement canonical_name in Formulary
This commit is contained in:
parent
e891bb4272
commit
20f4b31763
@ -390,44 +390,8 @@ class Formula
|
|||||||
Dir["#{HOMEBREW_LIBRARY}/Aliases/*"].map{ |f| File.basename f }.sort
|
Dir["#{HOMEBREW_LIBRARY}/Aliases/*"].map{ |f| File.basename f }.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO - document what this returns and why
|
|
||||||
def self.canonical_name name
|
def self.canonical_name name
|
||||||
# if name includes a '/', it may be a tap reference, path, or URL
|
Formulary.canonical_name(name)
|
||||||
if name.include? "/"
|
|
||||||
if name =~ %r{(.+)/(.+)/(.+)}
|
|
||||||
tap_name = "#$1-#$2".downcase
|
|
||||||
tapd = Pathname.new("#{HOMEBREW_LIBRARY}/Taps/#{tap_name}")
|
|
||||||
|
|
||||||
if tapd.directory?
|
|
||||||
tapd.find_formula do |relative_pathname|
|
|
||||||
return "#{tapd}/#{relative_pathname}" if relative_pathname.stem.to_s == $3
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
# Otherwise don't resolve paths or URLs
|
|
||||||
return name
|
|
||||||
end
|
|
||||||
|
|
||||||
# test if the name is a core formula
|
|
||||||
formula_with_that_name = Formula.path(name)
|
|
||||||
if formula_with_that_name.file? and formula_with_that_name.readable?
|
|
||||||
return name
|
|
||||||
end
|
|
||||||
|
|
||||||
# test if the name is a formula alias
|
|
||||||
possible_alias = Pathname.new("#{HOMEBREW_LIBRARY}/Aliases/#{name}")
|
|
||||||
if possible_alias.file?
|
|
||||||
return possible_alias.resolved_path.basename(".rb").to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
# test if the name is a cached downloaded formula
|
|
||||||
possible_cached_formula = Pathname.new("#{HOMEBREW_CACHE_FORMULA}/#{name}.rb")
|
|
||||||
if possible_cached_formula.file?
|
|
||||||
return possible_cached_formula.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
# dunno, pass through the name
|
|
||||||
return name
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.[](name)
|
def self.[](name)
|
||||||
|
|||||||
@ -178,6 +178,10 @@ class Formulary
|
|||||||
loader_for(ref).get_formula
|
loader_for(ref).get_formula
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.canonical_name(ref)
|
||||||
|
loader_for(ref).name
|
||||||
|
end
|
||||||
|
|
||||||
def self.loader_for(ref)
|
def self.loader_for(ref)
|
||||||
case ref
|
case ref
|
||||||
when %r[(https?|ftp)://]
|
when %r[(https?|ftp)://]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user