hbc/auditor: refactor and fix bug
Use instance methods to DRY things up, and fix a bug discovered in caskroom/homebrew-cask#26067 where Casks with language blocks would always fail audit.
This commit is contained in:
parent
b481ed73a0
commit
4ed51d8240
@ -1,32 +1,63 @@
|
|||||||
module Hbc
|
module Hbc
|
||||||
class Auditor
|
class Auditor
|
||||||
def self.audit(cask, audit_download: false, check_token_conflicts: false)
|
def self.audit(cask, audit_download: false, check_token_conflicts: false)
|
||||||
if !ARGV.value("language") &&
|
new(cask, audit_download, check_token_conflicts).audit
|
||||||
languages_blocks = cask.instance_variable_get(:@dsl).instance_variable_get(:@language_blocks)
|
end
|
||||||
begin
|
|
||||||
saved_languages = MacOS.instance_variable_get(:@languages)
|
|
||||||
|
|
||||||
languages_blocks.keys.map do |languages|
|
attr_reader :cask
|
||||||
ohai "Auditing language: #{languages.map { |lang| "'#{lang}'" }.join(", ")}"
|
|
||||||
MacOS.instance_variable_set(:@languages, languages)
|
def initialize(cask, audit_download, check_token_conflicts)
|
||||||
audit_cask_instance(Hbc.load(cask.sourcefile_path), audit_download, check_token_conflicts)
|
@cask = cask
|
||||||
CLI::Cleanup.run(cask.token) if audit_download
|
@audit_download = audit_download
|
||||||
end.all?
|
@check_token_conflicts = check_token_conflicts
|
||||||
ensure
|
end
|
||||||
MacOS.instance_variable_set(:@languages, saved_languages)
|
|
||||||
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
|
else
|
||||||
audit_cask_instance(cask, audit_download, check_token_conflicts)
|
audit_cask_instance(cask)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.audit_cask_instance(cask, audit_download, check_token_conflicts)
|
private
|
||||||
download = audit_download && Download.new(cask)
|
|
||||||
|
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,
|
audit = Audit.new(cask, download: download,
|
||||||
check_token_conflicts: check_token_conflicts)
|
check_token_conflicts: check_token_conflicts?)
|
||||||
audit.run!
|
audit.run!
|
||||||
puts audit.summary
|
puts audit.summary
|
||||||
audit.success?
|
audit.success?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def language_blocks
|
||||||
|
cask.instance_variable_get(:@dsl).instance_variable_get(:@language_blocks)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user