tap: add cask methods.

This commit is contained in:
Anastasia Sulyagina 2016-08-04 14:37:37 +04:00 committed by Mike McQuaid
parent b77a695b7a
commit 4338f35b84
2 changed files with 16 additions and 1 deletions

View File

@ -193,7 +193,7 @@ class Reporter
dst = Pathname.new paths.last dst = Pathname.new paths.last
next unless dst.extname == ".rb" next unless dst.extname == ".rb"
next unless paths.any? { |p| tap.formula_file?(p)} next unless paths.any? { |p| tap.formula_file?(p) || tap.cask_file?(p)}
case status case status
when "A", "D" when "A", "D"

View File

@ -72,6 +72,7 @@ class Tap
def clear_cache def clear_cache
@remote = nil @remote = nil
@formula_dir = nil @formula_dir = nil
@cask_dir = nil
@formula_files = nil @formula_files = nil
@alias_dir = nil @alias_dir = nil
@alias_files = nil @alias_files = nil
@ -304,6 +305,11 @@ class Tap
@formula_dir ||= [path/"Formula", path/"HomebrewFormula", path].detect(&:directory?) @formula_dir ||= [path/"Formula", path/"HomebrewFormula", path].detect(&:directory?)
end end
# path to the directory of all casks for caskroom/cask {Tap}.
def cask_dir
@cask_dir ||= path/"Casks"
end
# an array of all {Formula} files of this {Tap}. # an array of all {Formula} files of this {Tap}.
def formula_files def formula_files
@formula_files ||= if formula_dir @formula_files ||= if formula_dir
@ -322,6 +328,15 @@ class Tap
file.extname == ".rb" && file.parent == formula_dir file.extname == ".rb" && file.parent == formula_dir
end end
# return true if given path would present a cask file in this {Tap}.
# accepts both absolute path and relative path (relative to this {Tap}'s path)
# @private
def cask_file?(file)
file = Pathname.new(file) unless file.is_a? Pathname
file = file.expand_path(path)
file.extname == ".rb" && file.parent == cask_dir
end
# an array of all {Formula} names of this {Tap}. # an array of all {Formula} names of this {Tap}.
def formula_names def formula_names
@formula_names ||= formula_files.map { |f| formula_file_to_name(f) } @formula_names ||= formula_files.map { |f| formula_file_to_name(f) }