Add cask_files
method to Tap
class.
This commit is contained in:
parent
7820489831
commit
89a63fb177
@ -33,18 +33,14 @@ class Hbc::CLI::Doctor < Hbc::CLI::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.alt_taps
|
def self.alt_taps
|
||||||
Tap.select { |t| t.cask_dir.directory? && t != Hbc.default_tap }
|
Tap.select { |t| t.cask_dir && t != Hbc.default_tap }
|
||||||
.map(&:path)
|
.map(&:path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.default_cask_count
|
def self.default_cask_count
|
||||||
default_cask_count = notfound_string
|
Hbc.default_tap.cask_files.count
|
||||||
begin
|
rescue StandardError
|
||||||
default_cask_count = Hbc.default_tap.cask_dir.children.count(&:file?)
|
"0 #{error_string "Error reading #{Hbc.default_tap.path}"}"
|
||||||
rescue StandardError
|
|
||||||
default_cask_count = "0 #{error_string "Error reading #{Hbc.default_tap.path}"}"
|
|
||||||
end
|
|
||||||
default_cask_count
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.homebrew_origin
|
def self.homebrew_origin
|
||||||
|
@ -21,7 +21,7 @@ class Hbc::CLI::Search < Hbc::CLI::Base
|
|||||||
partial_matches = Hbc::CLI.nice_listing(Hbc.all_tokens).grep(%r{#{search_regexp}}i)
|
partial_matches = Hbc::CLI.nice_listing(Hbc.all_tokens).grep(%r{#{search_regexp}}i)
|
||||||
else
|
else
|
||||||
# suppressing search of the font Tap is a quick hack until behavior can be made configurable
|
# suppressing search of the font Tap is a quick hack until behavior can be made configurable
|
||||||
all_tokens = Hbc::CLI.nice_listing Hbc.all_tokens.reject { |t| %r{^caskroom/homebrew-fonts/}.match(t) }
|
all_tokens = Hbc::CLI.nice_listing Hbc.all_tokens.reject { |t| %r{^caskroom/fonts/}.match(t) }
|
||||||
simplified_tokens = all_tokens.map { |t| t.sub(%r{^.*\/}, "").gsub(%r{[^a-z0-9]+}i, "") }
|
simplified_tokens = all_tokens.map { |t| t.sub(%r{^.*\/}, "").gsub(%r{[^a-z0-9]+}i, "") }
|
||||||
simplified_search_term = search_term.sub(%r{\.rb$}i, "").gsub(%r{[^a-z0-9]+}i, "")
|
simplified_search_term = search_term.sub(%r{\.rb$}i, "").gsub(%r{[^a-z0-9]+}i, "")
|
||||||
exact_match = simplified_tokens.grep(%r{^#{simplified_search_term}$}i) { |t| all_tokens[simplified_tokens.index(t)] }.first
|
exact_match = simplified_tokens.grep(%r{^#{simplified_search_term}$}i) { |t| all_tokens[simplified_tokens.index(t)] }.first
|
||||||
|
@ -10,29 +10,15 @@ module Hbc::Scopes
|
|||||||
end
|
end
|
||||||
|
|
||||||
def all_tapped_cask_dirs
|
def all_tapped_cask_dirs
|
||||||
@all_tapped_cask_dirs ||= Tap.names.map(&Tap.method(:fetch)).map(&:cask_dir)
|
Tap.map(&:cask_dir).compact
|
||||||
.unshift(default_tap.cask_dir) # optimization: place the default Tap first
|
|
||||||
.uniq
|
|
||||||
end
|
|
||||||
|
|
||||||
def reset_all_tapped_cask_dirs
|
|
||||||
# The memoized value should be reset when a Tap is added/removed
|
|
||||||
# (which is a rare event in our codebase).
|
|
||||||
@all_tapped_cask_dirs = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def all_tokens
|
def all_tokens
|
||||||
cask_tokens = all_tapped_cask_dirs.map { |d| Dir.glob d.join("*.rb") }.flatten
|
Tap.map { |t|
|
||||||
cask_tokens.map { |c|
|
t.cask_files.map { |p|
|
||||||
# => "/usr/local/Library/Taps/caskroom/example-tap/Casks/example.rb"
|
"#{t.name}/#{File.basename(p, ".rb")}"
|
||||||
c.sub!(%r{\.rb$}, "")
|
}
|
||||||
# => ".../example"
|
}.flatten
|
||||||
c = c.split("/").last 4
|
|
||||||
# => ["caskroom", "example-tap", "Casks", "example"]
|
|
||||||
c.delete_at(-2)
|
|
||||||
# => ["caskroom", "example-tap", "example"]
|
|
||||||
c.join "/"
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def installed
|
def installed
|
||||||
|
@ -290,13 +290,22 @@ class Tap
|
|||||||
|
|
||||||
# path to the directory of all {Cask} files for this {Tap}.
|
# path to the directory of all {Cask} files for this {Tap}.
|
||||||
def cask_dir
|
def cask_dir
|
||||||
@cask_dir ||= path/"Casks"
|
@cask_dir ||= [path/"Casks"].detect(&:directory?)
|
||||||
end
|
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
|
||||||
formula_dir.children.select { |p| p.extname == ".rb" }
|
formula_dir.children.select(&method(:formula_file?))
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# an array of all {Cask} files of this {Tap}.
|
||||||
|
def cask_files
|
||||||
|
@cask_files ||= if cask_dir
|
||||||
|
cask_dir.children.select(&method(:cask_file?))
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
@ -311,7 +320,7 @@ 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}.
|
# 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)
|
# accepts both absolute path and relative path (relative to this {Tap}'s path)
|
||||||
# @private
|
# @private
|
||||||
def cask_file?(file)
|
def cask_file?(file)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user