From fac17e8459c193e40144c5e7875f5b634d8af9a0 Mon Sep 17 00:00:00 2001 From: Xu Cheng Date: Mon, 10 Aug 2015 21:35:59 +0800 Subject: [PATCH] to_rack: simplify the logic Closes Homebrew/homebrew#42743. Signed-off-by: Xu Cheng --- Library/Homebrew/formulary.rb | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 8fcffb59e0..6735859ca0 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -196,21 +196,14 @@ class Formulary end def self.to_rack(ref) - name = canonical_name(ref) - rack = HOMEBREW_CELLAR/name - - # Handle the case when ref is an old name and the installation - # hasn't been migrated or when it's a package installed from - # path but same name formula was renamed. - unless rack.directory? - if ref =~ HOMEBREW_TAP_FORMULA_REGEX - rack = HOMEBREW_CELLAR/$3 - elsif !ref.include?("/") - rack = HOMEBREW_CELLAR/ref - end + # First, check whether the rack with the given name exists. + if (rack = HOMEBREW_CELLAR/File.basename(ref, ".rb")).directory? + return rack end - rack + # Second, use canonical name to locate rack. + name = canonical_name(ref) + HOMEBREW_CELLAR/name end def self.canonical_name(ref)