diff options
| author | Josh Hagins | 2016-10-29 11:40:39 -0400 |
|---|---|---|
| committer | GitHub | 2016-10-29 11:40:39 -0400 |
| commit | 2605521ca9cc9088ce179509b691e976c4ac354c (patch) | |
| tree | de8cad344e5a952b128eeb6299f1595b21ab3897 /Library | |
| parent | 8a7317aa8ff5f12067eb65e529a13490bc69deda (diff) | |
| parent | 4ed51d82406e5edd44cbc28eb3444d7a618320ed (diff) | |
| download | brew-2605521ca9cc9088ce179509b691e976c4ac354c.tar.bz2 | |
Merge pull request #1361 from jawshooah/cask/refactor-auditor
hbc/auditor: refactor and fix bug
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/auditor.rb | 67 |
1 files changed, 49 insertions, 18 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/auditor.rb b/Library/Homebrew/cask/lib/hbc/auditor.rb index e2d5dea0e..c2ffbebda 100644 --- a/Library/Homebrew/cask/lib/hbc/auditor.rb +++ b/Library/Homebrew/cask/lib/hbc/auditor.rb @@ -1,32 +1,63 @@ module Hbc class Auditor def self.audit(cask, audit_download: false, check_token_conflicts: false) - if !ARGV.value("language") && - languages_blocks = cask.instance_variable_get(:@dsl).instance_variable_get(:@language_blocks) - begin - saved_languages = MacOS.instance_variable_get(:@languages) - - languages_blocks.keys.map do |languages| - ohai "Auditing language: #{languages.map { |lang| "'#{lang}'" }.join(", ")}" - MacOS.instance_variable_set(:@languages, languages) - audit_cask_instance(Hbc.load(cask.sourcefile_path), audit_download, check_token_conflicts) - CLI::Cleanup.run(cask.token) if audit_download - end.all? - ensure - MacOS.instance_variable_set(:@languages, saved_languages) - end + new(cask, audit_download, check_token_conflicts).audit + end + + attr_reader :cask + + def initialize(cask, audit_download, check_token_conflicts) + @cask = cask + @audit_download = audit_download + @check_token_conflicts = check_token_conflicts + end + + def audit_download? + @audit_download + end + + def check_token_conflicts? + @check_token_conflicts + end + + def audit + if !ARGV.value("language") && language_blocks + audit_all_languages else - audit_cask_instance(cask, audit_download, check_token_conflicts) + audit_cask_instance(cask) end end - def self.audit_cask_instance(cask, audit_download, check_token_conflicts) - download = audit_download && Download.new(cask) + private + + def audit_all_languages + saved_languages = MacOS.instance_variable_get(:@languages) + begin + language_blocks.keys.all?(&method(:audit_languages)) + ensure + MacOS.instance_variable_set(:@languages, saved_languages) + end + end + + def audit_languages(languages) + ohai "Auditing language: #{languages.map { |lang| "'#{lang}'" }.join(", ")}" + MacOS.instance_variable_set(:@languages, languages) + audit_cask_instance(Hbc.load(cask.sourcefile_path)) + ensure + CLI::Cleanup.run(cask.token) if audit_download? + end + + def audit_cask_instance(cask) + download = audit_download? && Download.new(cask) audit = Audit.new(cask, download: download, - check_token_conflicts: check_token_conflicts) + check_token_conflicts: check_token_conflicts?) audit.run! puts audit.summary audit.success? end + + def language_blocks + cask.instance_variable_get(:@dsl).instance_variable_get(:@language_blocks) + end end end |
