aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib
diff options
context:
space:
mode:
authorMarkus Reiter2017-03-16 22:58:21 +0100
committerGitHub2017-03-16 22:58:21 +0100
commitbfb5bf1d7007821c74de4252fe1ade5047e0ca3c (patch)
treefc9991edb93017eaab5fe4b26f781a45ad909b77 /Library/Homebrew/cask/lib
parentc4d8b1696c90fa54f0e2f4bce3c734f7a657662b (diff)
parented10135da4fbabca2798afe949b6f5af9544ec9f (diff)
downloadbrew-bfb5bf1d7007821c74de4252fe1ade5047e0ca3c.tar.bz2
Merge pull request #2325 from reitermarkus/better-cask-loading
Use a `Formulary`-like approach to load Casks.
Diffstat (limited to 'Library/Homebrew/cask/lib')
-rw-r--r--Library/Homebrew/cask/lib/hbc.rb9
-rw-r--r--Library/Homebrew/cask/lib/hbc/cask_dependencies.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cask_loader.rb177
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/audit.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/cat.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/create.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/edit.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/fetch.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/home.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/info.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/install.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/internal_checkurl.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/list.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/outdated.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/reinstall.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/style.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/uninstall.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/zap.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/installer.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/locations.rb28
-rw-r--r--Library/Homebrew/cask/lib/hbc/scopes.rb16
-rw-r--r--Library/Homebrew/cask/lib/hbc/source.rb37
-rw-r--r--Library/Homebrew/cask/lib/hbc/source/gone.rb23
-rw-r--r--Library/Homebrew/cask/lib/hbc/source/path_base.rb29
-rw-r--r--Library/Homebrew/cask/lib/hbc/source/path_slash_optional.rb12
-rw-r--r--Library/Homebrew/cask/lib/hbc/source/path_slash_required.rb12
-rw-r--r--Library/Homebrew/cask/lib/hbc/source/tapped.rb24
-rw-r--r--Library/Homebrew/cask/lib/hbc/source/tapped_qualified.rb21
-rw-r--r--Library/Homebrew/cask/lib/hbc/source/untapped_qualified.rb14
-rw-r--r--Library/Homebrew/cask/lib/hbc/source/uri.rb32
-rw-r--r--Library/Homebrew/cask/lib/hbc/without_source.rb17
35 files changed, 179 insertions, 314 deletions
diff --git a/Library/Homebrew/cask/lib/hbc.rb b/Library/Homebrew/cask/lib/hbc.rb
index 363879574..5b94a1b55 100644
--- a/Library/Homebrew/cask/lib/hbc.rb
+++ b/Library/Homebrew/cask/lib/hbc.rb
@@ -7,7 +7,6 @@ require "hbc/auditor"
require "hbc/cache"
require "hbc/cask"
require "hbc/cask_loader"
-require "hbc/without_source"
require "hbc/caskroom"
require "hbc/checkable"
require "hbc/cli"
@@ -24,7 +23,6 @@ require "hbc/macos"
require "hbc/pkg"
require "hbc/qualified_token"
require "hbc/scopes"
-require "hbc/source"
require "hbc/staged"
require "hbc/system_command"
require "hbc/topological_hash"
@@ -44,11 +42,4 @@ module Hbc
Cache.ensure_cache_exists
Caskroom.ensure_caskroom_exists
end
-
- def self.load(query)
- odebug "Loading Cask definitions"
- cask = Source.for_query(query).load
- cask.dumpcask
- cask
- end
end
diff --git a/Library/Homebrew/cask/lib/hbc/cask_dependencies.rb b/Library/Homebrew/cask/lib/hbc/cask_dependencies.rb
index fe5d1b743..8bba5df8e 100644
--- a/Library/Homebrew/cask/lib/hbc/cask_dependencies.rb
+++ b/Library/Homebrew/cask/lib/hbc/cask_dependencies.rb
@@ -15,7 +15,7 @@ module Hbc
walk = lambda do |acc, deps|
deps.each do |dep|
next if acc.key?(dep)
- succs = deps_in.call Hbc.load(dep)
+ succs = deps_in.call CaskLoader.load(dep)
acc[dep] = succs
walk.call(acc, succs)
end
diff --git a/Library/Homebrew/cask/lib/hbc/cask_loader.rb b/Library/Homebrew/cask/lib/hbc/cask_loader.rb
index 3fe02d7e1..c392e6b72 100644
--- a/Library/Homebrew/cask/lib/hbc/cask_loader.rb
+++ b/Library/Homebrew/cask/lib/hbc/cask_loader.rb
@@ -1,44 +1,167 @@
module Hbc
- class CaskLoader
- def self.load_from_file(path)
- raise CaskError, "File '#{path}' does not exist" unless path.exist?
- raise CaskError, "File '#{path}' is not readable" unless path.readable?
- raise CaskError, "File '#{path}' is not a plain file" unless path.file?
+ module CaskLoader
+ class FromContentLoader
+ def initialize(content)
+ @content = content
+ end
+
+ def load
+ instance_eval(@content.force_encoding("UTF-8"), __FILE__, __LINE__)
+ end
- token = path.basename(".rb").to_s
- content = IO.read(path).force_encoding("UTF-8")
+ private
- new(token, content, path).load
+ def cask(header_token, &block)
+ Cask.new(header_token, &block)
+ end
end
- def self.load_from_string(token, content)
- new(token, content).load
+ class FromPathLoader < FromContentLoader
+ def self.can_load?(ref)
+ path = Pathname.new(ref)
+ path.extname == ".rb" && path.expand_path.exist?
+ end
+
+ attr_reader :token, :path
+
+ def initialize(path)
+ path = Pathname.new(path).expand_path
+
+ @token = path.basename(".rb").to_s
+ @path = path
+ end
+
+ def load
+ raise CaskError, "'#{@path}' does not exist." unless @path.exist?
+ raise CaskError, "'#{@path}' is not readable." unless @path.readable?
+ raise CaskError, "'#{@path}' is not a file." unless @path.file?
+
+ @content = IO.read(@path)
+
+ super
+ end
+
+ private
+
+ def cask(header_token, &block)
+ if @token != header_token
+ raise CaskTokenDoesNotMatchError.new(@token, header_token)
+ end
+
+ Cask.new(header_token, sourcefile_path: @path, &block)
+ end
end
- def load
- instance_eval(@content, __FILE__, __LINE__)
- rescue CaskError, StandardError, ScriptError => e
- e.message.concat(" while loading '#{@token}'")
- e.message.concat(" from '#{@path}'") unless @path.nil?
- raise e, e.message
+ class FromURILoader < FromPathLoader
+ def self.can_load?(ref)
+ !(ref.to_s !~ ::URI.regexp)
+ end
+
+ def initialize(url)
+ @url = url
+ uri = URI(url)
+ super Hbc.cache/File.basename(uri.path)
+ end
+
+ def load
+ Hbc.cache.mkpath
+ FileUtils.rm_f @path
+
+ begin
+ ohai "Downloading #{@url}."
+ curl @url, "-o", @path
+ rescue ErrorDuringExecution
+ raise CaskUnavailableError, @url
+ end
+
+ super
+ end
end
- private
+ class FromTapLoader < FromPathLoader
+ def self.can_load?(ref)
+ !(ref.to_s !~ HOMEBREW_TAP_CASK_REGEX)
+ end
+
+ def initialize(tapped_name)
+ user, repo, token = tapped_name.split("/", 3).map(&:downcase)
+ @tap = Tap.fetch(user, repo)
+
+ super @tap.cask_dir/"#{token}.rb"
+ end
- def initialize(token, content, path = nil)
- @token = token
- @content = content
- @path = path unless path.nil?
+ def load
+ @tap.install unless @tap.installed?
+
+ super
+ end
+ end
+
+ class NullLoader < FromPathLoader
+ def self.can_load?(*)
+ true
+ end
+
+ def initialize(ref)
+ @token = File.basename(ref, ".rb")
+ super CaskLoader.default_path(@token)
+ end
+
+ def load
+ raise CaskUnavailableError, @token
+ end
+ end
+
+ def self.load_from_file(path)
+ FromPathLoader.new(path).load
+ end
+
+ def self.load_from_string(content)
+ FromContentLoader.new(content).load
end
- def cask(header_token, &block)
- raise CaskTokenDoesNotMatchError.new(@token, header_token) unless @token == header_token
+ def self.path(ref)
+ self.for(ref).path
+ end
+
+ def self.load(ref)
+ self.for(ref).load
+ end
+
+ def self.for(ref)
+ [
+ FromURILoader,
+ FromTapLoader,
+ FromPathLoader,
+ ].each do |loader_class|
+ return loader_class.new(ref) if loader_class.can_load?(ref)
+ end
+
+ if FromPathLoader.can_load?(default_path(ref))
+ return FromPathLoader.new(default_path(ref))
+ end
- if @path.nil?
- Cask.new(@token, &block)
- else
- Cask.new(@token, sourcefile_path: @path, &block)
+ possible_tap_casks = tap_paths(ref)
+ if possible_tap_casks.count == 1
+ possible_tap_cask = possible_tap_casks.first
+ return FromPathLoader.new(possible_tap_cask)
end
+
+ possible_installed_cask = Cask.new(ref)
+ if possible_installed_cask.installed?
+ return FromPathLoader.new(possible_installed_cask.installed_caskfile)
+ end
+
+ NullLoader.new(ref)
+ end
+
+ def self.default_path(token)
+ Hbc.default_tap.cask_dir/"#{token.to_s.downcase}.rb"
+ end
+
+ def self.tap_paths(token)
+ Tap.map { |t| t.cask_dir/"#{token.to_s.downcase}.rb" }
+ .select(&:exist?)
end
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/audit.rb b/Library/Homebrew/cask/lib/hbc/cli/audit.rb
index a06f71c60..ec1c33754 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/audit.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/audit.rb
@@ -40,7 +40,7 @@ module Hbc
if cask_tokens.empty?
Hbc.all
else
- cask_tokens.map { |token| Hbc.load(token) }
+ cask_tokens.map { |token| CaskLoader.load(token) }
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/cat.rb b/Library/Homebrew/cask/lib/hbc/cli/cat.rb
index 464e23a5e..52f6e0eab 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/cat.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/cat.rb
@@ -6,7 +6,7 @@ module Hbc
raise CaskUnspecifiedError if cask_tokens.empty?
# only respects the first argument
cask_token = cask_tokens.first.sub(/\.rb$/i, "")
- cask_path = Hbc.path(cask_token)
+ cask_path = CaskLoader.path(cask_token)
raise CaskUnavailableError, cask_token.to_s unless cask_path.exist?
puts File.open(cask_path, &:read)
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/create.rb b/Library/Homebrew/cask/lib/hbc/cli/create.rb
index 3e2b9c191..5e143d085 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/create.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/create.rb
@@ -5,7 +5,7 @@ module Hbc
cask_tokens = cask_tokens_from(args)
raise CaskUnspecifiedError if cask_tokens.empty?
cask_token = cask_tokens.first.sub(/\.rb$/i, "")
- cask_path = Hbc.path(cask_token)
+ cask_path = CaskLoader.path(cask_token)
odebug "Creating Cask #{cask_token}"
raise CaskAlreadyCreatedError, cask_token if cask_path.exist?
diff --git a/Library/Homebrew/cask/lib/hbc/cli/edit.rb b/Library/Homebrew/cask/lib/hbc/cli/edit.rb
index a6cb9e209..1f1e0d918 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/edit.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/edit.rb
@@ -6,7 +6,7 @@ module Hbc
raise CaskUnspecifiedError if cask_tokens.empty?
# only respects the first argument
cask_token = cask_tokens.first.sub(/\.rb$/i, "")
- cask_path = Hbc.path(cask_token)
+ cask_path = CaskLoader.path(cask_token)
odebug "Opening editor for Cask #{cask_token}"
unless cask_path.exist?
raise CaskUnavailableError, %Q(#{cask_token}, run "brew cask create #{cask_token}" to create a new Cask)
diff --git a/Library/Homebrew/cask/lib/hbc/cli/fetch.rb b/Library/Homebrew/cask/lib/hbc/cli/fetch.rb
index fc928586f..83dba672c 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/fetch.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/fetch.rb
@@ -8,7 +8,7 @@ module Hbc
cask_tokens.each do |cask_token|
ohai "Downloading external files for Cask #{cask_token}"
- cask = Hbc.load(cask_token)
+ cask = CaskLoader.load(cask_token)
downloaded_path = Download.new(cask, force: force).perform
Verify.all(cask, downloaded_path)
ohai "Success! Downloaded to -> #{downloaded_path}"
diff --git a/Library/Homebrew/cask/lib/hbc/cli/home.rb b/Library/Homebrew/cask/lib/hbc/cli/home.rb
index 4734bfebb..66be49186 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/home.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/home.rb
@@ -8,7 +8,7 @@ module Hbc
else
cask_tokens.each do |cask_token|
odebug "Opening homepage for Cask #{cask_token}"
- cask = Hbc.load(cask_token)
+ cask = CaskLoader.load(cask_token)
system "/usr/bin/open", "--", cask.homepage
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb
index 8701166af..625b4ecae 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/info.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb
@@ -6,7 +6,7 @@ module Hbc
raise CaskUnspecifiedError if cask_tokens.empty?
cask_tokens.each do |cask_token|
odebug "Getting info for Cask #{cask_token}"
- cask = Hbc.load(cask_token)
+ cask = CaskLoader.load(cask_token)
info(cask)
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/install.rb b/Library/Homebrew/cask/lib/hbc/cli/install.rb
index 3f4c94b6b..438f860c1 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/install.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/install.rb
@@ -18,7 +18,7 @@ module Hbc
count = 0
cask_tokens.each do |cask_token|
begin
- cask = Hbc.load(cask_token)
+ cask = CaskLoader.load(cask_token)
Installer.new(cask,
force: force,
skip_cask_deps: skip_cask_deps,
diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb
index 790e917b2..da3567108 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb
@@ -24,7 +24,7 @@ module Hbc
count = 0
cask_tokens.each do |cask_token|
- cask = Hbc.load(cask_token)
+ cask = CaskLoader.load(cask_token)
if cask.appcast.nil?
opoo "Cask '#{cask}' is missing an `appcast` stanza."
diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb
index 60df4bc8c..9467cccc7 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb
@@ -84,7 +84,7 @@ module Hbc
def modified_casks
return @modified_casks if defined? @modified_casks
- @modified_casks = modified_cask_files.map { |f| Hbc.load(f) }
+ @modified_casks = modified_cask_files.map { |f| CaskLoader.load(f) }
if @modified_casks.any?
num_modified = @modified_casks.size
ohai "#{Formatter.pluralize(num_modified, "modified cask")}: " \
diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_checkurl.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_checkurl.rb
index 77cf250b1..b7d95957d 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/internal_checkurl.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/internal_checkurl.rb
@@ -2,7 +2,7 @@ module Hbc
class CLI
class InternalCheckurl < InternalUseBase
def self.run(*args)
- casks_to_check = args.empty? ? Hbc.all : args.map { |arg| Hbc.load(arg) }
+ casks_to_check = args.empty? ? Hbc.all : args.map { |arg| CaskLoader.load(arg) }
casks_to_check.each do |cask|
odebug "Checking URL for Cask #{cask}"
checker = UrlChecker.new(cask)
diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb
index 36a1ca74b..8017a32cf 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb
@@ -16,7 +16,7 @@ module Hbc
count = 0
cask_tokens.each do |cask_token|
begin
- cask = Hbc.load(cask_token)
+ cask = CaskLoader.load(cask_token)
count += 1
cask.dumpcask
rescue StandardError => e
diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb
index c54db8795..303aa7ffe 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb
@@ -84,7 +84,7 @@ module Hbc
print "#{cask_token}\t" if table
begin
- cask = Hbc.load(cask_token)
+ cask = CaskLoader.load(cask_token)
rescue StandardError
opoo "Cask '#{cask_token}' was not found" unless quiet
puts ""
diff --git a/Library/Homebrew/cask/lib/hbc/cli/list.rb b/Library/Homebrew/cask/lib/hbc/cli/list.rb
index 51ca5dabe..d9bf2187b 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/list.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/list.rb
@@ -28,7 +28,7 @@ module Hbc
cask_tokens.each do |cask_token|
odebug "Listing files for Cask #{cask_token}"
begin
- cask = Hbc.load(cask_token)
+ cask = CaskLoader.load(cask_token)
if cask.installed?
if @options[:one]
diff --git a/Library/Homebrew/cask/lib/hbc/cli/outdated.rb b/Library/Homebrew/cask/lib/hbc/cli/outdated.rb
index d608beab5..5956f59ac 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/outdated.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/outdated.rb
@@ -9,7 +9,7 @@ module Hbc
casks_to_check = if cask_tokens.empty?
Hbc.installed
else
- cask_tokens.map { |token| Hbc.load(token) }
+ cask_tokens.map { |token| CaskLoader.load(token) }
end
casks_to_check.each do |cask|
diff --git a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb
index c101c9235..b52c43328 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb
@@ -5,7 +5,7 @@ module Hbc
count = 0
cask_tokens.each do |cask_token|
begin
- cask = Hbc.load(cask_token)
+ cask = CaskLoader.load(cask_token)
installer = Installer.new(cask,
force: force,
diff --git a/Library/Homebrew/cask/lib/hbc/cli/style.rb b/Library/Homebrew/cask/lib/hbc/cli/style.rb
index f38d785fc..191aefd3c 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/style.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/style.rb
@@ -39,7 +39,7 @@ module Hbc
elsif cask_tokens.any? { |file| File.exist?(file) }
cask_tokens
else
- cask_tokens.map { |token| Hbc.path(token) }
+ cask_tokens.map { |token| CaskLoader.path(token) }
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb
index d74b59d4c..6887aaf4f 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb
@@ -8,7 +8,7 @@ module Hbc
cask_tokens.each do |cask_token|
odebug "Uninstalling Cask #{cask_token}"
- cask = Hbc.load(cask_token)
+ cask = CaskLoader.load(cask_token)
raise CaskNotInstalledError, cask unless cask.installed? || force
diff --git a/Library/Homebrew/cask/lib/hbc/cli/zap.rb b/Library/Homebrew/cask/lib/hbc/cli/zap.rb
index 2f9723858..83da1c932 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/zap.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/zap.rb
@@ -6,7 +6,7 @@ module Hbc
raise CaskUnspecifiedError if cask_tokens.empty?
cask_tokens.each do |cask_token|
odebug "Zapping Cask #{cask_token}"
- cask = Hbc.load(cask_token)
+ cask = CaskLoader.load(cask_token)
Installer.new(cask).zap
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb
index 94d270946..824c1b1be 100644
--- a/Library/Homebrew/cask/lib/hbc/installer.rb
+++ b/Library/Homebrew/cask/lib/hbc/installer.rb
@@ -229,7 +229,7 @@ module Hbc
deps = CaskDependencies.new(@cask)
deps.sorted.each do |dep_token|
puts "#{dep_token} ..."
- dep = Hbc.load(dep_token)
+ dep = CaskLoader.load(dep_token)
if dep.installed?
puts "already installed"
else
diff --git a/Library/Homebrew/cask/lib/hbc/locations.rb b/Library/Homebrew/cask/lib/hbc/locations.rb
index 80add91dd..e55bdf15d 100644
--- a/Library/Homebrew/cask/lib/hbc/locations.rb
+++ b/Library/Homebrew/cask/lib/hbc/locations.rb
@@ -109,34 +109,6 @@ module Hbc
@default_tap ||= Tap.fetch("caskroom", "homebrew-cask")
end
- def path(query)
- query_path = Pathname.new(query)
-
- return query_path if query_path.absolute?
- return query_path if query_path.exist? && query_path.extname == ".rb"
-
- query_without_extension = query.sub(/\.rb$/i, "")
-
- token_with_tap = if query =~ %r{\A[^/]+/[^/]+/[^/]+\Z}
- query_without_extension
- else
- all_tokens.detect do |tap_and_token|
- tap_and_token.split("/")[2] == query_without_extension
- end
- end
-
- if token_with_tap
- user, repo, token = token_with_tap.split("/")
- tap = Tap.fetch(user, repo)
- else
- token = query_without_extension
- tap = Hbc.default_tap
- end
-
- return query_path if tap.cask_dir.nil?
- tap.cask_dir.join("#{token}.rb")
- end
-
def tcc_db
@tcc_db ||= Pathname.new("/Library/Application Support/com.apple.TCC/TCC.db")
end
diff --git a/Library/Homebrew/cask/lib/hbc/scopes.rb b/Library/Homebrew/cask/lib/hbc/scopes.rb
index aa870eec5..db12409e5 100644
--- a/Library/Homebrew/cask/lib/hbc/scopes.rb
+++ b/Library/Homebrew/cask/lib/hbc/scopes.rb
@@ -11,22 +11,22 @@ module Hbc
end
def all_tapped_cask_dirs
- Tap.map(&:cask_dir).compact
+ Tap.map(&:cask_dir).select(&:directory?)
end
def all_tokens
- Tap.map do |t|
+ Tap.flat_map do |t|
t.cask_files.map do |p|
"#{t.name}/#{File.basename(p, ".rb")}"
end
- end.flatten
+ end
end
def installed
- # Hbc.load has some DWIM which is slow. Optimize here
- # by spoon-feeding Hbc.load fully-qualified paths.
+ # CaskLoader.load has some DWIM which is slow. Optimize here
+ # by spoon-feeding CaskLoader.load fully-qualified paths.
# TODO: speed up Hbc::Source::Tapped (main perf drag is calling Hbc.all_tokens repeatedly)
- # TODO: ability to specify expected source when calling Hbc.load (minor perf benefit)
+ # TODO: ability to specify expected source when calling CaskLoader.load (minor perf benefit)
Pathname.glob(caskroom.join("*"))
.map do |caskroom_path|
token = caskroom_path.basename.to_s
@@ -36,9 +36,9 @@ module Hbc
end
if path_to_cask
- Hbc.load(path_to_cask.join("#{token}.rb"))
+ CaskLoader.load(path_to_cask.join("#{token}.rb"))
else
- Hbc.load(token)
+ CaskLoader.load(token)
end
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/source.rb b/Library/Homebrew/cask/lib/hbc/source.rb
deleted file mode 100644
index 5f2e9ddfe..000000000
--- a/Library/Homebrew/cask/lib/hbc/source.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-require "hbc/source/gone"
-require "hbc/source/path_slash_required"
-require "hbc/source/path_slash_optional"
-require "hbc/source/tapped_qualified"
-require "hbc/source/untapped_qualified"
-require "hbc/source/tapped"
-require "hbc/source/uri"
-
-module Hbc
- module Source
- def self.sources
- [
- URI,
- PathSlashRequired,
- TappedQualified,
- UntappedQualified,
- Tapped,
- PathSlashOptional,
- Gone,
- ]
- end
-
- def self.for_query(query)
- odebug "Translating '#{query}' into a valid Cask source"
- raise CaskUnavailableError, query if query.to_s =~ /^\s*$/
- source = sources.find do |s|
- odebug "Testing source class #{s}"
- s.me?(query)
- end
- raise CaskUnavailableError, query unless source
- odebug "Success! Using source class #{source}"
- resolved_cask_source = source.new(query)
- odebug "Resolved Cask URI or file source to '#{resolved_cask_source}'"
- resolved_cask_source
- end
- end
-end
diff --git a/Library/Homebrew/cask/lib/hbc/source/gone.rb b/Library/Homebrew/cask/lib/hbc/source/gone.rb
deleted file mode 100644
index 1c744d0db..000000000
--- a/Library/Homebrew/cask/lib/hbc/source/gone.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-module Hbc
- module Source
- class Gone
- def self.me?(query)
- WithoutSource.new(query).installed?
- end
-
- attr_reader :query
-
- def initialize(query)
- @query = query
- end
-
- def load
- WithoutSource.new(query)
- end
-
- def to_s
- ""
- end
- end
- end
-end
diff --git a/Library/Homebrew/cask/lib/hbc/source/path_base.rb b/Library/Homebrew/cask/lib/hbc/source/path_base.rb
deleted file mode 100644
index 4e4bdcf15..000000000
--- a/Library/Homebrew/cask/lib/hbc/source/path_base.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-require "rubygems"
-require "hbc/cask_loader"
-
-module Hbc
- module Source
- class PathBase
- # derived classes must define method self.me?
-
- def self.path_for_query(query)
- Pathname.new(query).sub(/(\.rb)?$/, ".rb")
- end
-
- attr_reader :path
-
- def initialize(path)
- @path = Pathname.new(path).expand_path
- end
-
- def load
- CaskLoader.load_from_file(@path)
- end
-
- def to_s
- # stringify to fully-resolved location
- @path.to_s
- end
- end
- end
-end
diff --git a/Library/Homebrew/cask/lib/hbc/source/path_slash_optional.rb b/Library/Homebrew/cask/lib/hbc/source/path_slash_optional.rb
deleted file mode 100644
index d96a41130..000000000
--- a/Library/Homebrew/cask/lib/hbc/source/path_slash_optional.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require "hbc/source/path_base"
-
-module Hbc
- module Source
- class PathSlashOptional < PathBase
- def self.me?(query)
- path = path_for_query(query)
- path.exist?
- end
- end
- end
-end
diff --git a/Library/Homebrew/cask/lib/hbc/source/path_slash_required.rb b/Library/Homebrew/cask/lib/hbc/source/path_slash_required.rb
deleted file mode 100644
index 2753b1710..000000000
--- a/Library/Homebrew/cask/lib/hbc/source/path_slash_required.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require "hbc/source/path_base"
-
-module Hbc
- module Source
- class PathSlashRequired < PathBase
- def self.me?(query)
- path = path_for_query(query)
- path.to_s.include?("/") && path.exist?
- end
- end
- end
-end
diff --git a/Library/Homebrew/cask/lib/hbc/source/tapped.rb b/Library/Homebrew/cask/lib/hbc/source/tapped.rb
deleted file mode 100644
index c1f5f95bc..000000000
--- a/Library/Homebrew/cask/lib/hbc/source/tapped.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-module Hbc
- module Source
- class Tapped
- def self.me?(query)
- Hbc.path(query).exist?
- end
-
- attr_reader :token
-
- def initialize(token)
- @token = token
- end
-
- def load
- PathSlashOptional.new(Hbc.path(token)).load
- end
-
- def to_s
- # stringify to fully-resolved location
- Hbc.path(token).expand_path.to_s
- end
- end
- end
-end
diff --git a/Library/Homebrew/cask/lib/hbc/source/tapped_qualified.rb b/Library/Homebrew/cask/lib/hbc/source/tapped_qualified.rb
deleted file mode 100644
index 2db6ddbca..000000000
--- a/Library/Homebrew/cask/lib/hbc/source/tapped_qualified.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require "hbc/source/tapped"
-
-module Hbc
- module Source
- class TappedQualified < Tapped
- def self.me?(query)
- return if (tap = tap_for_query(query)).nil?
-
- tap.installed? && Hbc.path(query).exist?
- end
-
- def self.tap_for_query(query)
- qualified_token = QualifiedToken.parse(query)
- return if qualified_token.nil?
-
- user, repo = qualified_token[0..1]
- Tap.fetch(user, repo)
- end
- end
- end
-end
diff --git a/Library/Homebrew/cask/lib/hbc/source/untapped_qualified.rb b/Library/Homebrew/cask/lib/hbc/source/untapped_qualified.rb
deleted file mode 100644
index 698cc46ce..000000000
--- a/Library/Homebrew/cask/lib/hbc/source/untapped_qualified.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-require "hbc/source/tapped_qualified"
-
-module Hbc
- module Source
- class UntappedQualified < TappedQualified
- def self.me?(query)
- return if (tap = tap_for_query(query)).nil?
-
- tap.install
- tap.installed? && Hbc.path(query).exist?
- end
- end
- end
-end
diff --git a/Library/Homebrew/cask/lib/hbc/source/uri.rb b/Library/Homebrew/cask/lib/hbc/source/uri.rb
deleted file mode 100644
index 09fab4bd0..000000000
--- a/Library/Homebrew/cask/lib/hbc/source/uri.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-module Hbc
- module Source
- class URI
- def self.me?(query)
- !(query.to_s =~ ::URI.regexp).nil?
- end
-
- attr_reader :uri
-
- def initialize(uri)
- @uri = uri
- end
-
- def load
- Hbc.cache.mkpath
- path = Hbc.cache.join(File.basename(uri))
- ohai "Downloading #{uri}"
- odebug "Download target -> #{path}"
- begin
- curl(uri, "-o", path.to_s)
- rescue ErrorDuringExecution
- raise CaskUnavailableError, uri
- end
- PathSlashOptional.new(path).load
- end
-
- def to_s
- uri.to_s
- end
- end
- end
-end
diff --git a/Library/Homebrew/cask/lib/hbc/without_source.rb b/Library/Homebrew/cask/lib/hbc/without_source.rb
deleted file mode 100644
index 69131d5c7..000000000
--- a/Library/Homebrew/cask/lib/hbc/without_source.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-module Hbc
- class WithoutSource < Cask
- # Override from `Hbc::DSL` because we don't have a cask source file to work
- # with, so we don't know the cask's `version`.
- def staged_path
- (caskroom_path.children - [metadata_master_container_path]).first
- end
-
- def to_s
- "#{token} (!)"
- end
-
- def installed?
- caskroom_path.exist?
- end
- end
-end