aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorXu Cheng2015-12-06 22:16:08 +0800
committerXu Cheng2015-12-09 16:56:59 +0800
commit5debd5b132690bced97171b9ad31575c6a74dfe0 (patch)
tree4b133d984a6323d6a08dd9c59c8fa06ff9af5cfa /Library
parent6e92609cf42c18a84c0eefd3e7dea56856330f76 (diff)
downloadbrew-5debd5b132690bced97171b9ad31575c6a74dfe0.tar.bz2
Formula#tap: returns tap object
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/formula.rb54
1 files changed, 24 insertions, 30 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index da9431ebc..d7e5ffc49 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -68,6 +68,11 @@ class Formula
# e.g. `/usr/local/Library/Formula/this-formula.rb`
attr_reader :path
+ # The {Tap} instance associated with this {Formula}.
+ # If it's <code>nil</code>, then this formula is loaded from path or URL.
+ # @private
+ attr_reader :tap
+
# The stable (and default) {SoftwareSpec} for this {Formula}
# This contains all the attributes (e.g. URL, checksum) that apply to the
# stable version of this formula.
@@ -133,9 +138,14 @@ class Formula
@path = path
@revision = self.class.revision || 0
- if path.to_s =~ HOMEBREW_TAP_PATH_REGEX
- @full_name = "#{Tap.fetch($1, $2)}/#{name}"
+ if path == Formulary.core_path(name)
+ @tap = CoreFormulaRepository.instance
+ @full_name = name
+ elsif path.to_s =~ HOMEBREW_TAP_PATH_REGEX
+ @tap = Tap.fetch($1, $2)
+ @full_name = "#{@tap}/#{name}"
else
+ @tap = nil
@full_name = name
end
@@ -290,13 +300,8 @@ class Formula
# An old name for the formula
def oldname
- @oldname ||= if core_formula?
- if FORMULA_RENAMES && FORMULA_RENAMES.value?(name)
- FORMULA_RENAMES.to_a.rassoc(name).first
- end
- elsif tap?
- user, repo = tap.split("/")
- formula_renames = Tap.fetch(user, repo).formula_renames
+ @oldname ||= if tap
+ formula_renames = tap.formula_renames
if formula_renames.value?(name)
formula_renames.to_a.rassoc(name).first
end
@@ -305,11 +310,8 @@ class Formula
# All of aliases for the formula
def aliases
- @aliases ||= if core_formula?
- Formula.core_alias_reverse_table[name] || []
- elsif tap?
- user, repo = tap.split("/")
- Tap.fetch(user, repo).alias_reverse_table[full_name] || []
+ @aliases ||= if tap
+ tap.alias_reverse_table[full_name] || []
else
[]
end
@@ -873,8 +875,8 @@ class Formula
rescue NotAKegError, Errno::ENOENT
# file doesn't belong to any keg.
else
- tap = Tab.for_keg(keg).tap
- return false if tap.nil? # this keg doesn't below to any core/tap formula, most likely coming from a DIY install.
+ tab_tap = Tab.for_keg(keg).tap
+ return false if tab_tap.nil? # this keg doesn't below to any core/tap formula, most likely coming from a DIY install.
begin
Formulary.factory(keg.name)
rescue FormulaUnavailableError
@@ -1173,18 +1175,16 @@ class Formula
Formulary.factory(name)
end
+ # True if this formula is provided by Homebrew itself
# @private
- def tap?
- HOMEBREW_TAP_DIR_REGEX === path
+ def core_formula?
+ tap && tap.core_formula_repository?
end
+ # True if this formula is provided by external Tap
# @private
- def tap
- if path.to_s =~ HOMEBREW_TAP_DIR_REGEX
- "#{$1}/#{$2}"
- elsif core_formula?
- "Homebrew/homebrew"
- end
+ def tap?
+ tap && !tap.core_formula_repository?
end
# @private
@@ -1195,12 +1195,6 @@ class Formula
end
end
- # True if this formula is provided by Homebrew itself
- # @private
- def core_formula?
- path == Formulary.core_path(name)
- end
-
# @private
def env
self.class.env