Skip to content
Snippets Groups Projects
Commit 20f4b317 authored by Jack Nagel's avatar Jack Nagel
Browse files

Implement canonical_name in Formulary

parent e891bb42
No related branches found
No related tags found
No related merge requests found
......@@ -390,44 +390,8 @@ class Formula
Dir["#{HOMEBREW_LIBRARY}/Aliases/*"].map{ |f| File.basename f }.sort
end
# TODO - document what this returns and why
def self.canonical_name name
# if name includes a '/', it may be a tap reference, path, or URL
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
Formulary.canonical_name(name)
end
def self.[](name)
......
......@@ -178,6 +178,10 @@ class Formulary
loader_for(ref).get_formula
end
def self.canonical_name(ref)
loader_for(ref).name
end
def self.loader_for(ref)
case ref
when %r[(https?|ftp)://]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment