From d1995dad4bf76b447d9c97f1c2db99c6b3854b51 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 12 Mar 2017 19:18:41 +0100 Subject: [PATCH 1/3] Use a `Formulary`-like approach to load Casks. --- Library/Homebrew/cask/lib/hbc.rb | 9 +- Library/Homebrew/cask/lib/hbc/cask_loader.rb | 201 ++++++++++++++---- Library/Homebrew/cask/lib/hbc/locations.rb | 5 +- Library/Homebrew/cask/lib/hbc/scopes.rb | 6 +- Library/Homebrew/cask/lib/hbc/source.rb | 37 ---- Library/Homebrew/cask/lib/hbc/source/gone.rb | 23 -- .../Homebrew/cask/lib/hbc/source/path_base.rb | 29 --- .../lib/hbc/source/path_slash_optional.rb | 12 -- .../lib/hbc/source/path_slash_required.rb | 12 -- .../Homebrew/cask/lib/hbc/source/tapped.rb | 24 --- .../cask/lib/hbc/source/tapped_qualified.rb | 21 -- .../cask/lib/hbc/source/untapped_qualified.rb | 14 -- Library/Homebrew/cask/lib/hbc/source/uri.rb | 32 --- .../Homebrew/cask/lib/hbc/without_source.rb | 17 -- Library/Homebrew/cmd/irb.rb | 5 + Library/Homebrew/compat/hbc/cask_loader.rb | 8 +- Library/Homebrew/tap.rb | 8 +- Library/Homebrew/test/cask/cli/list_spec.rb | 17 -- 18 files changed, 184 insertions(+), 296 deletions(-) delete mode 100644 Library/Homebrew/cask/lib/hbc/source.rb delete mode 100644 Library/Homebrew/cask/lib/hbc/source/gone.rb delete mode 100644 Library/Homebrew/cask/lib/hbc/source/path_base.rb delete mode 100644 Library/Homebrew/cask/lib/hbc/source/path_slash_optional.rb delete mode 100644 Library/Homebrew/cask/lib/hbc/source/path_slash_required.rb delete mode 100644 Library/Homebrew/cask/lib/hbc/source/tapped.rb delete mode 100644 Library/Homebrew/cask/lib/hbc/source/tapped_qualified.rb delete mode 100644 Library/Homebrew/cask/lib/hbc/source/untapped_qualified.rb delete mode 100644 Library/Homebrew/cask/lib/hbc/source/uri.rb delete mode 100644 Library/Homebrew/cask/lib/hbc/without_source.rb diff --git a/Library/Homebrew/cask/lib/hbc.rb b/Library/Homebrew/cask/lib/hbc.rb index 363879574d..4f22a643d8 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" @@ -45,10 +43,7 @@ module Hbc Caskroom.ensure_caskroom_exists end - def self.load(query) - odebug "Loading Cask definitions" - cask = Source.for_query(query).load - cask.dumpcask - cask + def self.load(ref) + CaskLoader.load(ref) end end diff --git a/Library/Homebrew/cask/lib/hbc/cask_loader.rb b/Library/Homebrew/cask/lib/hbc/cask_loader.rb index 3fe02d7e15..c392e6b727 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? - - token = path.basename(".rb").to_s - content = IO.read(path).force_encoding("UTF-8") - - new(token, content, path).load - end - - def self.load_from_string(token, content) - new(token, content).load - 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 - end - - private - - def initialize(token, content, path = nil) - @token = token - @content = content - @path = path unless path.nil? - end - - def cask(header_token, &block) - raise CaskTokenDoesNotMatchError.new(@token, header_token) unless @token == header_token - - if @path.nil? - Cask.new(@token, &block) - else - Cask.new(@token, sourcefile_path: @path, &block) + module CaskLoader + class FromContentLoader + def initialize(content) + @content = content end + + def load + instance_eval(@content.force_encoding("UTF-8"), __FILE__, __LINE__) + end + + private + + def cask(header_token, &block) + Cask.new(header_token, &block) + end + end + + 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 + + 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 + + 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 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 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 + + 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/locations.rb b/Library/Homebrew/cask/lib/hbc/locations.rb index 80add91dd5..c15cec32bf 100644 --- a/Library/Homebrew/cask/lib/hbc/locations.rb +++ b/Library/Homebrew/cask/lib/hbc/locations.rb @@ -126,15 +126,14 @@ module Hbc end if token_with_tap - user, repo, token = token_with_tap.split("/") + user, repo, token = token_with_tap.split("/", 3) 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") + CaskLoader.default_path(token) end def tcc_db diff --git a/Library/Homebrew/cask/lib/hbc/scopes.rb b/Library/Homebrew/cask/lib/hbc/scopes.rb index aa870eec55..fb26757358 100644 --- a/Library/Homebrew/cask/lib/hbc/scopes.rb +++ b/Library/Homebrew/cask/lib/hbc/scopes.rb @@ -11,15 +11,15 @@ 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 diff --git a/Library/Homebrew/cask/lib/hbc/source.rb b/Library/Homebrew/cask/lib/hbc/source.rb deleted file mode 100644 index 5f2e9ddfef..0000000000 --- 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 1c744d0dbb..0000000000 --- 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 4e4bdcf158..0000000000 --- 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 d96a41130d..0000000000 --- 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 2753b17109..0000000000 --- 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 c1f5f95bca..0000000000 --- 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 2db6ddbca5..0000000000 --- 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 698cc46ce6..0000000000 --- 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 09fab4bd0e..0000000000 --- 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 69131d5c70..0000000000 --- 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 diff --git a/Library/Homebrew/cmd/irb.rb b/Library/Homebrew/cmd/irb.rb index 5561845e72..cba8a5b82b 100644 --- a/Library/Homebrew/cmd/irb.rb +++ b/Library/Homebrew/cmd/irb.rb @@ -19,6 +19,11 @@ class String end end +def cask + $LOAD_PATH.unshift("#{HOMEBREW_LIBRARY_PATH}/cask/lib") + require "hbc" +end + module Homebrew module_function diff --git a/Library/Homebrew/compat/hbc/cask_loader.rb b/Library/Homebrew/compat/hbc/cask_loader.rb index a7c84e3ce8..e6cb65b4f2 100644 --- a/Library/Homebrew/compat/hbc/cask_loader.rb +++ b/Library/Homebrew/compat/hbc/cask_loader.rb @@ -12,7 +12,11 @@ module CaskLoaderCompatibilityLayer end module Hbc - class CaskLoader - prepend CaskLoaderCompatibilityLayer + module CaskLoader + class FromContentLoader; end + + class FromPathLoader < FromContentLoader + prepend CaskLoaderCompatibilityLayer + end end end diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 56e06834d9..ba55e3cf66 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -285,7 +285,7 @@ class Tap # path to the directory of all {Formula} files for this {Tap}. def formula_dir - @formula_dir ||= potential_formula_dirs.detect(&:directory?) + @formula_dir ||= potential_formula_dirs.detect(&:directory?) || path/"Formula" end def potential_formula_dirs @@ -294,12 +294,12 @@ class Tap # path to the directory of all {Cask} files for this {Tap}. def cask_dir - @cask_dir ||= [path/"Casks"].detect(&:directory?) + @cask_dir ||= path/"Casks" end # an array of all {Formula} files of this {Tap}. def formula_files - @formula_files ||= if formula_dir + @formula_files ||= if formula_dir.directory? formula_dir.children.select(&method(:formula_file?)) else [] @@ -308,7 +308,7 @@ class Tap # an array of all {Cask} files of this {Tap}. def cask_files - @cask_files ||= if cask_dir + @cask_files ||= if cask_dir.directory? cask_dir.children.select(&method(:cask_file?)) else [] diff --git a/Library/Homebrew/test/cask/cli/list_spec.rb b/Library/Homebrew/test/cask/cli/list_spec.rb index e367e95887..b53eb169ac 100644 --- a/Library/Homebrew/test/cask/cli/list_spec.rb +++ b/Library/Homebrew/test/cask/cli/list_spec.rb @@ -40,23 +40,6 @@ describe Hbc::CLI::List, :cask do end end - describe "when Casks have been renamed" do - let(:caskroom_path) { Hbc.caskroom.join("ive-been-renamed") } - let(:staged_path) { caskroom_path.join("latest") } - - before do - staged_path.mkpath - end - - it "lists installed Casks without backing ruby files (due to renames or otherwise)" do - expect { - Hbc::CLI::List.run - }.to output(<<-EOS.undent).to_stdout - ive-been-renamed (!) - EOS - end - end - describe "given a set of installed Casks" do let(:caffeine) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") } let(:transmission) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") } From d7af864be0e64c830a4c9944980bece19a60872d Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 13 Mar 2017 01:01:17 +0100 Subject: [PATCH 2/3] Replace `Hbc.path` with `CaskLoader.path`. --- Library/Homebrew/cask/lib/hbc/cli/cat.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/create.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/edit.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/style.rb | 2 +- Library/Homebrew/cask/lib/hbc/locations.rb | 27 ------------------- Library/Homebrew/test/cask/cli/create_spec.rb | 12 ++++----- Library/Homebrew/test/cask/cli/edit_spec.rb | 4 +-- Library/Homebrew/test/cask/cli/style_spec.rb | 2 +- 8 files changed, 13 insertions(+), 40 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/cat.rb b/Library/Homebrew/cask/lib/hbc/cli/cat.rb index 464e23a5e4..52f6e0eabe 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 3e2b9c1911..5e143d0859 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 a6cb9e2092..1f1e0d9181 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/style.rb b/Library/Homebrew/cask/lib/hbc/cli/style.rb index f38d785fc1..191aefd3c6 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/locations.rb b/Library/Homebrew/cask/lib/hbc/locations.rb index c15cec32bf..e55bdf15dc 100644 --- a/Library/Homebrew/cask/lib/hbc/locations.rb +++ b/Library/Homebrew/cask/lib/hbc/locations.rb @@ -109,33 +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("/", 3) - tap = Tap.fetch(user, repo) - else - token = query_without_extension - tap = Hbc.default_tap - end - - CaskLoader.default_path(token) - end - def tcc_db @tcc_db ||= Pathname.new("/Library/Application Support/com.apple.TCC/TCC.db") end diff --git a/Library/Homebrew/test/cask/cli/create_spec.rb b/Library/Homebrew/test/cask/cli/create_spec.rb index 21eaeb656f..b1cee69908 100644 --- a/Library/Homebrew/test/cask/cli/create_spec.rb +++ b/Library/Homebrew/test/cask/cli/create_spec.rb @@ -24,7 +24,7 @@ describe Hbc::CLI::Create, :cask do after(:each) do %w[new-cask additional-cask another-cask yet-another-cask local-caff].each do |cask| - path = Hbc.path(cask) + path = Hbc::CaskLoader.path(cask) path.delete if path.exist? end end @@ -32,13 +32,13 @@ describe Hbc::CLI::Create, :cask do it "opens the editor for the specified Cask" do Hbc::CLI::Create.run("new-cask") expect(Hbc::CLI::Create.editor_commands).to eq [ - [Hbc.path("new-cask")], + [Hbc::CaskLoader.path("new-cask")], ] end it "drops a template down for the specified Cask" do Hbc::CLI::Create.run("new-cask") - template = File.read(Hbc.path("new-cask")) + template = File.read(Hbc::CaskLoader.path("new-cask")) expect(template).to eq <<-EOS.undent cask 'new-cask' do version '' @@ -56,14 +56,14 @@ describe Hbc::CLI::Create, :cask do it "throws away additional Cask arguments and uses the first" do Hbc::CLI::Create.run("additional-cask", "another-cask") expect(Hbc::CLI::Create.editor_commands).to eq [ - [Hbc.path("additional-cask")], + [Hbc::CaskLoader.path("additional-cask")], ] end it "throws away stray options" do Hbc::CLI::Create.run("--notavalidoption", "yet-another-cask") expect(Hbc::CLI::Create.editor_commands).to eq [ - [Hbc.path("yet-another-cask")], + [Hbc::CaskLoader.path("yet-another-cask")], ] end @@ -76,7 +76,7 @@ describe Hbc::CLI::Create, :cask do it "allows creating Casks that are substrings of existing Casks" do Hbc::CLI::Create.run("local-caff") expect(Hbc::CLI::Create.editor_commands).to eq [ - [Hbc.path("local-caff")], + [Hbc::CaskLoader.path("local-caff")], ] end diff --git a/Library/Homebrew/test/cask/cli/edit_spec.rb b/Library/Homebrew/test/cask/cli/edit_spec.rb index 61970290b3..f5f98afc87 100644 --- a/Library/Homebrew/test/cask/cli/edit_spec.rb +++ b/Library/Homebrew/test/cask/cli/edit_spec.rb @@ -25,14 +25,14 @@ describe Hbc::CLI::Edit, :cask do it "opens the editor for the specified Cask" do Hbc::CLI::Edit.run("local-caffeine") expect(Hbc::CLI::Edit.editor_commands).to eq [ - [Hbc.path("local-caffeine")], + [Hbc::CaskLoader.path("local-caffeine")], ] end it "throws away additional arguments and uses the first" do Hbc::CLI::Edit.run("local-caffeine", "local-transmission") expect(Hbc::CLI::Edit.editor_commands).to eq [ - [Hbc.path("local-caffeine")], + [Hbc::CaskLoader.path("local-caffeine")], ] end diff --git a/Library/Homebrew/test/cask/cli/style_spec.rb b/Library/Homebrew/test/cask/cli/style_spec.rb index 3f2ec91e25..ca17c5e46e 100644 --- a/Library/Homebrew/test/cask/cli/style_spec.rb +++ b/Library/Homebrew/test/cask/cli/style_spec.rb @@ -130,7 +130,7 @@ describe Hbc::CLI::Style, :cask do end it "tries to find paths for all tokens" do - expect(Hbc).to receive(:path).twice + expect(Hbc::CaskLoader).to receive(:path).twice subject end end From ed10135da4fbabca2798afe949b6f5af9544ec9f Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 13 Mar 2017 01:09:36 +0100 Subject: [PATCH 3/3] Replace `Hbc.load` with `CaskLoader.load`. --- Library/Homebrew/cask/lib/hbc.rb | 4 ---- .../cask/lib/hbc/cask_dependencies.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/audit.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/fetch.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/home.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/info.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/install.rb | 2 +- .../hbc/cli/internal_appcast_checkpoint.rb | 2 +- .../hbc/cli/internal_audit_modified_casks.rb | 2 +- .../cask/lib/hbc/cli/internal_checkurl.rb | 2 +- .../cask/lib/hbc/cli/internal_dump.rb | 2 +- .../cask/lib/hbc/cli/internal_stanza.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/list.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/outdated.rb | 2 +- .../Homebrew/cask/lib/hbc/cli/reinstall.rb | 2 +- .../Homebrew/cask/lib/hbc/cli/uninstall.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/zap.rb | 2 +- Library/Homebrew/cask/lib/hbc/installer.rb | 2 +- Library/Homebrew/cask/lib/hbc/scopes.rb | 10 ++++----- Library/Homebrew/test/cask/audit_spec.rb | 4 ++-- Library/Homebrew/test/cask/cask_spec.rb | 22 +++++++++---------- Library/Homebrew/test/cask/cli/audit_spec.rb | 10 ++++----- Library/Homebrew/test/cask/cli/list_spec.rb | 4 ++-- Library/Homebrew/test/cask/cli/zap_spec.rb | 2 +- Library/Homebrew/test/cask/depends_on_spec.rb | 2 +- .../test/cask/download_strategy_spec.rb | 2 +- Library/Homebrew/test/cask/scopes_spec.rb | 12 +++++----- 27 files changed, 51 insertions(+), 55 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc.rb b/Library/Homebrew/cask/lib/hbc.rb index 4f22a643d8..5b94a1b55c 100644 --- a/Library/Homebrew/cask/lib/hbc.rb +++ b/Library/Homebrew/cask/lib/hbc.rb @@ -42,8 +42,4 @@ module Hbc Cache.ensure_cache_exists Caskroom.ensure_caskroom_exists end - - def self.load(ref) - CaskLoader.load(ref) - end end diff --git a/Library/Homebrew/cask/lib/hbc/cask_dependencies.rb b/Library/Homebrew/cask/lib/hbc/cask_dependencies.rb index fe5d1b7439..8bba5df8e7 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/cli/audit.rb b/Library/Homebrew/cask/lib/hbc/cli/audit.rb index a06f71c60d..ec1c33754e 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/fetch.rb b/Library/Homebrew/cask/lib/hbc/cli/fetch.rb index fc928586f2..83dba672c2 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 4734bfebb9..66be49186c 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 8701166af6..625b4ecae3 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 3f4c94b6b3..438f860c1c 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 790e917b22..da35671086 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 60df4bc8c7..9467cccc71 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 77cf250b1f..b7d95957d8 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 36a1ca74bb..8017a32cf7 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 c54db87957..303aa7ffe7 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 51ca5dabeb..d9bf2187b1 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 d608beab50..5956f59ac1 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 c101c9235d..b52c433282 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/uninstall.rb b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb index d74b59d4c6..6887aaf4fc 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 2f9723858f..83da1c932e 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 94d2709462..824c1b1beb 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/scopes.rb b/Library/Homebrew/cask/lib/hbc/scopes.rb index fb26757358..db12409e54 100644 --- a/Library/Homebrew/cask/lib/hbc/scopes.rb +++ b/Library/Homebrew/cask/lib/hbc/scopes.rb @@ -23,10 +23,10 @@ module Hbc 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/test/cask/audit_spec.rb b/Library/Homebrew/test/cask/audit_spec.rb index 802807fcb4..ddc773e3e2 100644 --- a/Library/Homebrew/test/cask/audit_spec.rb +++ b/Library/Homebrew/test/cask/audit_spec.rb @@ -79,7 +79,7 @@ describe Hbc::Audit, :cask do end describe "#run!" do - let(:cask) { Hbc.load(cask_token) } + let(:cask) { Hbc::CaskLoader.load(cask_token) } subject { audit.run! } describe "required stanzas" do @@ -320,7 +320,7 @@ describe Hbc::Audit, :cask do describe "audit of downloads" do let(:cask_token) { "with-binary" } - let(:cask) { Hbc.load(cask_token) } + let(:cask) { Hbc::CaskLoader.load(cask_token) } let(:download) { instance_double(Hbc::Download) } let(:verify) { class_double(Hbc::Verify).as_stubbed_const } let(:error_msg) { "Download Failed" } diff --git a/Library/Homebrew/test/cask/cask_spec.rb b/Library/Homebrew/test/cask/cask_spec.rb index 3971d3f9c0..2ab966f828 100644 --- a/Library/Homebrew/test/cask/cask_spec.rb +++ b/Library/Homebrew/test/cask/cask_spec.rb @@ -27,20 +27,20 @@ describe Hbc::Cask, :cask do let(:relative_tap_path) { tap_path.relative_path_from(file_dirname) } it "returns an instance of the Cask for the given token" do - c = Hbc.load("local-caffeine") + c = Hbc::CaskLoader.load("local-caffeine") expect(c).to be_kind_of(Hbc::Cask) expect(c.token).to eq("local-caffeine") end it "returns an instance of the Cask from a specific file location" do - c = Hbc.load("#{tap_path}/Casks/local-caffeine.rb") + c = Hbc::CaskLoader.load("#{tap_path}/Casks/local-caffeine.rb") expect(c).to be_kind_of(Hbc::Cask) expect(c.token).to eq("local-caffeine") end it "returns an instance of the Cask from a url" do c = shutup do - Hbc.load("file://#{tap_path}/Casks/local-caffeine.rb") + Hbc::CaskLoader.load("file://#{tap_path}/Casks/local-caffeine.rb") end expect(c).to be_kind_of(Hbc::Cask) expect(c.token).to eq("local-caffeine") @@ -50,25 +50,25 @@ describe Hbc::Cask, :cask do expect { url = "file://#{tap_path}/Casks/notacask.rb" shutup do - Hbc.load(url) + Hbc::CaskLoader.load(url) end }.to raise_error(Hbc::CaskUnavailableError) end it "returns an instance of the Cask from a relative file location" do - c = Hbc.load(relative_tap_path/"Casks/local-caffeine.rb") + c = Hbc::CaskLoader.load(relative_tap_path/"Casks/local-caffeine.rb") expect(c).to be_kind_of(Hbc::Cask) expect(c.token).to eq("local-caffeine") end it "uses exact match when loading by token" do - expect(Hbc.load("test-opera").token).to eq("test-opera") - expect(Hbc.load("test-opera-mail").token).to eq("test-opera-mail") + expect(Hbc::CaskLoader.load("test-opera").token).to eq("test-opera") + expect(Hbc::CaskLoader.load("test-opera-mail").token).to eq("test-opera-mail") end it "raises an error when attempting to load a Cask that doesn't exist" do expect { - Hbc.load("notacask") + Hbc::CaskLoader.load("notacask") }.to raise_error(Hbc::CaskUnavailableError) end end @@ -84,7 +84,7 @@ describe Hbc::Cask, :cask do describe "metadata" do it "proposes a versioned metadata directory name for each instance" do cask_token = "local-caffeine" - c = Hbc.load(cask_token) + c = Hbc::CaskLoader.load(cask_token) metadata_path = Hbc.caskroom.join(cask_token, ".metadata", c.version) expect(c.metadata_versioned_container_path.to_s).to eq(metadata_path.to_s) end @@ -92,13 +92,13 @@ describe Hbc::Cask, :cask do describe "outdated" do it "ignores the Casks that have auto_updates true (without --greedy)" do - c = Hbc.load("auto-updates") + c = Hbc::CaskLoader.load("auto-updates") expect(c).not_to be_outdated expect(c.outdated_versions).to be_empty end it "ignores the Casks that have version :latest (without --greedy)" do - c = Hbc.load("version-latest-string") + c = Hbc::CaskLoader.load("version-latest-string") expect(c).not_to be_outdated expect(c.outdated_versions).to be_empty end diff --git a/Library/Homebrew/test/cask/cli/audit_spec.rb b/Library/Homebrew/test/cask/cli/audit_spec.rb index 2736e60c15..007ba1eb3e 100644 --- a/Library/Homebrew/test/cask/cli/audit_spec.rb +++ b/Library/Homebrew/test/cask/cli/audit_spec.rb @@ -13,7 +13,7 @@ describe Hbc::CLI::Audit, :cask do it "audits specified Casks if tokens are given" do cask_token = "nice-app" - expect(Hbc).to receive(:load).with(cask_token).and_return(cask) + expect(Hbc::CaskLoader).to receive(:load).with(cask_token).and_return(cask) expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: false) @@ -23,14 +23,14 @@ describe Hbc::CLI::Audit, :cask do describe "rules for downloading a Cask" do it "does not download the Cask per default" do - allow(Hbc).to receive(:load).and_return(cask) + allow(Hbc::CaskLoader).to receive(:load).and_return(cask) expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: false) run_audit(["casktoken"], auditor) end it "download a Cask if --download flag is set" do - allow(Hbc).to receive(:load).and_return(cask) + allow(Hbc::CaskLoader).to receive(:load).and_return(cask) expect(auditor).to receive(:audit).with(cask, audit_download: true, check_token_conflicts: false) run_audit(["casktoken", "--download"], auditor) @@ -39,14 +39,14 @@ describe Hbc::CLI::Audit, :cask do describe "rules for checking token conflicts" do it "does not check for token conflicts per default" do - allow(Hbc).to receive(:load).and_return(cask) + allow(Hbc::CaskLoader).to receive(:load).and_return(cask) expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: false) run_audit(["casktoken"], auditor) end it "checks for token conflicts if --token-conflicts flag is set" do - allow(Hbc).to receive(:load).and_return(cask) + allow(Hbc::CaskLoader).to receive(:load).and_return(cask) expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: true) run_audit(["casktoken", "--token-conflicts"], auditor) diff --git a/Library/Homebrew/test/cask/cli/list_spec.rb b/Library/Homebrew/test/cask/cli/list_spec.rb index b53eb169ac..d3fee73066 100644 --- a/Library/Homebrew/test/cask/cli/list_spec.rb +++ b/Library/Homebrew/test/cask/cli/list_spec.rb @@ -1,6 +1,6 @@ describe Hbc::CLI::List, :cask do it "lists the installed Casks in a pretty fashion" do - casks = %w[local-caffeine local-transmission].map { |c| Hbc.load(c) } + casks = %w[local-caffeine local-transmission].map { |c| Hbc::CaskLoader.load(c) } casks.each do |c| InstallHelper.install_with_caskfile(c) @@ -24,7 +24,7 @@ describe Hbc::CLI::List, :cask do } before(:each) do - casks.map(&Hbc.method(:load)).each(&InstallHelper.method(:install_with_caskfile)) + casks.map(&Hbc::CaskLoader.method(:load)).each(&InstallHelper.method(:install_with_caskfile)) end it "of all installed Casks" do diff --git a/Library/Homebrew/test/cask/cli/zap_spec.rb b/Library/Homebrew/test/cask/cli/zap_spec.rb index 0f3d024b5c..58992deb53 100644 --- a/Library/Homebrew/test/cask/cli/zap_spec.rb +++ b/Library/Homebrew/test/cask/cli/zap_spec.rb @@ -32,7 +32,7 @@ describe Hbc::CLI::Zap, :cask do # The above tests that implicitly. # # it "dispatches both uninstall and zap stanzas" do - # with_zap = Hbc.load('with-zap') + # with_zap = Hbc::CaskLoader.load('with-zap') # # shutup do # Hbc::Installer.new(with_zap).install diff --git a/Library/Homebrew/test/cask/depends_on_spec.rb b/Library/Homebrew/test/cask/depends_on_spec.rb index 81fda23293..0299c243a6 100644 --- a/Library/Homebrew/test/cask/depends_on_spec.rb +++ b/Library/Homebrew/test/cask/depends_on_spec.rb @@ -17,7 +17,7 @@ describe "Satisfy Dependencies and Requirements", :cask do context do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask.rb") } - let(:dependency) { Hbc.load(cask.depends_on.cask.first) } + let(:dependency) { Hbc::CaskLoader.load(cask.depends_on.cask.first) } it "installs the dependency of a Cask and the Cask itself" do expect(subject).not_to raise_error diff --git a/Library/Homebrew/test/cask/download_strategy_spec.rb b/Library/Homebrew/test/cask/download_strategy_spec.rb index 416a830eae..91fe934be4 100644 --- a/Library/Homebrew/test/cask/download_strategy_spec.rb +++ b/Library/Homebrew/test/cask/download_strategy_spec.rb @@ -291,7 +291,7 @@ describe "download strategies", :cask do # does not work yet, because (for unknown reasons), the tar command # returns an error code when running under the test suite # it 'creates a tarball matching the expected checksum' do - # cask = Hbc.load('svn-download-check-cask') + # cask = Hbc::CaskLoader.load('svn-download-check-cask') # downloader = Hbc::SubversionDownloadStrategy.new(cask) # # special mocking required for tar to have something to work with # def downloader.fetch_repo(target, url, revision = nil, ignore_externals=false) diff --git a/Library/Homebrew/test/cask/scopes_spec.rb b/Library/Homebrew/test/cask/scopes_spec.rb index 330683b2a7..d1c03b9b0c 100644 --- a/Library/Homebrew/test/cask/scopes_spec.rb +++ b/Library/Homebrew/test/cask/scopes_spec.rb @@ -1,15 +1,15 @@ describe Hbc::Scopes, :cask do describe "installed" do it "returns a list installed Casks by loading Casks for all the dirs that exist in the caskroom" do - allow(Hbc).to receive(:load) { |token| "loaded-#{token}" } + allow(Hbc::CaskLoader).to receive(:load) { |token| "loaded-#{token}" } Hbc.caskroom.join("cask-bar").mkpath Hbc.caskroom.join("cask-foo").mkpath installed_casks = Hbc.installed - expect(Hbc).to have_received(:load).with("cask-bar") - expect(Hbc).to have_received(:load).with("cask-foo") + expect(Hbc::CaskLoader).to have_received(:load).with("cask-bar") + expect(Hbc::CaskLoader).to have_received(:load).with("cask-foo") expect(installed_casks).to eq( %w[ loaded-cask-bar @@ -18,11 +18,11 @@ describe Hbc::Scopes, :cask do ) end - it "optimizes performance by resolving to a fully qualified path before calling Hbc.load" do + it "optimizes performance by resolving to a fully qualified path before calling Hbc::CaskLoader.load" do fake_tapped_cask_dir = Pathname.new(Dir.mktmpdir).join("Casks") absolute_path_to_cask = fake_tapped_cask_dir.join("some-cask.rb") - allow(Hbc).to receive(:load) + allow(Hbc::CaskLoader).to receive(:load) allow(Hbc).to receive(:all_tapped_cask_dirs) { [fake_tapped_cask_dir] } Hbc.caskroom.join("some-cask").mkdir @@ -31,7 +31,7 @@ describe Hbc::Scopes, :cask do Hbc.installed - expect(Hbc).to have_received(:load).with(absolute_path_to_cask) + expect(Hbc::CaskLoader).to have_received(:load).with(absolute_path_to_cask) end end end