Formula#tap: returns tap object

This commit is contained in:
Xu Cheng 2015-12-06 22:16:08 +08:00
parent 6e92609cf4
commit 5debd5b132

View File

@ -68,6 +68,11 @@ class Formula
# e.g. `/usr/local/Library/Formula/this-formula.rb` # e.g. `/usr/local/Library/Formula/this-formula.rb`
attr_reader :path 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} # The stable (and default) {SoftwareSpec} for this {Formula}
# This contains all the attributes (e.g. URL, checksum) that apply to the # This contains all the attributes (e.g. URL, checksum) that apply to the
# stable version of this formula. # stable version of this formula.
@ -133,9 +138,14 @@ class Formula
@path = path @path = path
@revision = self.class.revision || 0 @revision = self.class.revision || 0
if path.to_s =~ HOMEBREW_TAP_PATH_REGEX if path == Formulary.core_path(name)
@full_name = "#{Tap.fetch($1, $2)}/#{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 else
@tap = nil
@full_name = name @full_name = name
end end
@ -290,13 +300,8 @@ class Formula
# An old name for the formula # An old name for the formula
def oldname def oldname
@oldname ||= if core_formula? @oldname ||= if tap
if FORMULA_RENAMES && FORMULA_RENAMES.value?(name) formula_renames = tap.formula_renames
FORMULA_RENAMES.to_a.rassoc(name).first
end
elsif tap?
user, repo = tap.split("/")
formula_renames = Tap.fetch(user, repo).formula_renames
if formula_renames.value?(name) if formula_renames.value?(name)
formula_renames.to_a.rassoc(name).first formula_renames.to_a.rassoc(name).first
end end
@ -305,11 +310,8 @@ class Formula
# All of aliases for the formula # All of aliases for the formula
def aliases def aliases
@aliases ||= if core_formula? @aliases ||= if tap
Formula.core_alias_reverse_table[name] || [] tap.alias_reverse_table[full_name] || []
elsif tap?
user, repo = tap.split("/")
Tap.fetch(user, repo).alias_reverse_table[full_name] || []
else else
[] []
end end
@ -873,8 +875,8 @@ class Formula
rescue NotAKegError, Errno::ENOENT rescue NotAKegError, Errno::ENOENT
# file doesn't belong to any keg. # file doesn't belong to any keg.
else else
tap = Tab.for_keg(keg).tap tab_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. return false if tab_tap.nil? # this keg doesn't below to any core/tap formula, most likely coming from a DIY install.
begin begin
Formulary.factory(keg.name) Formulary.factory(keg.name)
rescue FormulaUnavailableError rescue FormulaUnavailableError
@ -1173,18 +1175,16 @@ class Formula
Formulary.factory(name) Formulary.factory(name)
end end
# True if this formula is provided by Homebrew itself
# @private # @private
def tap? def core_formula?
HOMEBREW_TAP_DIR_REGEX === path tap && tap.core_formula_repository?
end end
# True if this formula is provided by external Tap
# @private # @private
def tap def tap?
if path.to_s =~ HOMEBREW_TAP_DIR_REGEX tap && !tap.core_formula_repository?
"#{$1}/#{$2}"
elsif core_formula?
"Homebrew/homebrew"
end
end end
# @private # @private
@ -1195,12 +1195,6 @@ class Formula
end end
end end
# True if this formula is provided by Homebrew itself
# @private
def core_formula?
path == Formulary.core_path(name)
end
# @private # @private
def env def env
self.class.env self.class.env