diff options
| author | Adam Vandenberg | 2013-06-23 13:51:57 -0700 |
|---|---|---|
| committer | Adam Vandenberg | 2013-06-23 18:42:18 -0700 |
| commit | 2c1172d64ba058cbe1c7be01f2f2fe6ca181e74f (patch) | |
| tree | e126694845df2e18030133f989dc51d808fbfc98 /Library | |
| parent | 34fb41411b608bd64814216907b3ea0bcfb13010 (diff) | |
| download | homebrew-2c1172d64ba058cbe1c7be01f2f2fe6ca181e74f.tar.bz2 | |
document canonical name and move vars down to usage
Closes #20719.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/formula.rb | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 6f642ce90..e8d045ff5 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 |
