From 66fc5fa48a2a00a90b1ba147207606cf1c6f5221 Mon Sep 17 00:00:00 2001 From: Adam Vandenberg Date: Sun, 23 Jun 2013 13:51:57 -0700 Subject: [PATCH] document canonical name and move vars down to usage Closes Homebrew/homebrew#20719. --- Library/Homebrew/formula.rb | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 6f642ce902..e8d045ff55 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -357,10 +357,7 @@ class Formula def self.canonical_name name name = name.to_s if name.kind_of? Pathname - formula_with_that_name = Pathname.new("#{HOMEBREW_REPOSITORY}/Library/Formula/#{name}.rb") - possible_alias = Pathname.new("#{HOMEBREW_REPOSITORY}/Library/Aliases/#{name}") - possible_cached_formula = Pathname.new("#{HOMEBREW_CACHE_FORMULA}/#{name}.rb") - + # if name includes a '/', it may be a tap reference, path, or URL if name.include? "/" if name =~ %r{(.+)/(.+)/(.+)} tap_name = "#$1-#$2".downcase @@ -370,16 +367,29 @@ class Formula end if tapd.directory? end # Otherwise don't resolve paths or URLs - name - elsif formula_with_that_name.file? and formula_with_that_name.readable? - name - elsif possible_alias.file? - possible_alias.realpath.basename('.rb').to_s - elsif possible_cached_formula.file? - possible_cached_formula.to_s - else - name + return name end + + # test if the name is a core formula + formula_with_that_name = Pathname.new("#{HOMEBREW_REPOSITORY}/Library/Formula/#{name}.rb") + 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_REPOSITORY}/Library/Aliases/#{name}") + if possible_alias.file? + return possible_alias.realpath.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 def self.factory name