From 97333df4cb4bd006401193639400a8bc6df56e3a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 7 Oct 2017 15:58:49 +0200 Subject: Add helper method for Cask fixture paths and refactor CaskLoader. --- Library/Homebrew/cask/lib/hbc/audit.rb | 2 +- Library/Homebrew/cask/lib/hbc/auditor.rb | 2 +- Library/Homebrew/cask/lib/hbc/cask_loader.rb | 15 +++++++-------- Library/Homebrew/cask/lib/hbc/cli/list.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/uninstall.rb | 2 +- Library/Homebrew/cask/lib/hbc/installer.rb | 2 +- 6 files changed, 12 insertions(+), 13 deletions(-) (limited to 'Library/Homebrew/cask') diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb index 9ab93a67f..c15fa6307 100644 --- a/Library/Homebrew/cask/lib/hbc/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/audit.rb @@ -71,7 +71,7 @@ module Hbc return if previous_cask_contents.empty? begin - previous_cask = CaskLoader.load_from_string(previous_cask_contents) + previous_cask = CaskLoader.load(previous_cask_contents) return unless previous_cask.version == cask.version return if previous_cask.sha256 == cask.sha256 diff --git a/Library/Homebrew/cask/lib/hbc/auditor.rb b/Library/Homebrew/cask/lib/hbc/auditor.rb index 48f36a54d..231c005f9 100644 --- a/Library/Homebrew/cask/lib/hbc/auditor.rb +++ b/Library/Homebrew/cask/lib/hbc/auditor.rb @@ -43,7 +43,7 @@ module Hbc def audit_languages(languages) ohai "Auditing language: #{languages.map { |lang| "'#{lang}'" }.join(", ")}" MacOS.instance_variable_set(:@languages, languages) - audit_cask_instance(CaskLoader.load_from_file(cask.sourcefile_path)) + audit_cask_instance(CaskLoader.load(cask.sourcefile_path)) ensure CLI::Cleanup.run(cask.token) if audit_download? end diff --git a/Library/Homebrew/cask/lib/hbc/cask_loader.rb b/Library/Homebrew/cask/lib/hbc/cask_loader.rb index 8fce9636a..5660992da 100644 --- a/Library/Homebrew/cask/lib/hbc/cask_loader.rb +++ b/Library/Homebrew/cask/lib/hbc/cask_loader.rb @@ -147,14 +147,6 @@ module Hbc 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 @@ -164,6 +156,13 @@ module Hbc end def self.for(ref) + if ref.respond_to?(:to_str) + content = ref.to_str + if content.match?(/\A\s*cask\s+(?:"[^"]*"|'[^']*')\s+do(?:\s+.*\s+|;?\s+)end\s*\Z/) + return FromContentLoader.new(content) + end + end + [ FromInstanceLoader, FromURILoader, diff --git a/Library/Homebrew/cask/lib/hbc/cli/list.rb b/Library/Homebrew/cask/lib/hbc/cli/list.rb index 32415af8a..72b78d110 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/list.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/list.rb @@ -23,7 +23,7 @@ module Hbc elsif versions? puts self.class.format_versioned(cask) else - cask = CaskLoader.load_from_file(cask.installed_caskfile) + cask = CaskLoader.load(cask.installed_caskfile) self.class.list_artifacts(cask) end end diff --git a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb index 7e55db5f1..f2059605c 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb @@ -16,7 +16,7 @@ module Hbc if cask.installed? && !cask.installed_caskfile.nil? # use the same cask file that was used for installation, if possible - cask = CaskLoader.load_from_file(cask.installed_caskfile) if cask.installed_caskfile.exist? + cask = CaskLoader.load(cask.installed_caskfile) if cask.installed_caskfile.exist? end Installer.new(cask, binaries: binaries?, verbose: verbose?, force: force?).uninstall diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 01aae935d..ee4494a62 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -126,7 +126,7 @@ module Hbc # use the same cask file that was used for installation, if possible installed_caskfile = @cask.installed_caskfile - installed_cask = installed_caskfile.exist? ? CaskLoader.load_from_file(installed_caskfile) : @cask + installed_cask = installed_caskfile.exist? ? CaskLoader.load(installed_caskfile) : @cask # Always force uninstallation, ignore method parameter Installer.new(installed_cask, binaries: binaries?, verbose: verbose?, force: true).uninstall -- cgit v1.2.3