aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorL. E. Segovia2017-10-30 20:47:22 -0300
committerL. E. Segovia2017-10-30 20:47:22 -0300
commit9b6b0bfed7f0ebf461d21dba9ba12ad340e20508 (patch)
treea636040f6d25c664374a7273bdc86f5e813c08bd /Library
parent809e82038894da86a49f634e2b798db21e09a852 (diff)
downloadbrew-9b6b0bfed7f0ebf461d21dba9ba12ad340e20508.tar.bz2
Use #count, rewrite warning, and add pre/postflight checks too
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cask/lib/hbc/audit.rb21
1 files changed, 13 insertions, 8 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb
index e4349dc2d..4a5a40e4f 100644
--- a/Library/Homebrew/cask/lib/hbc/audit.rb
+++ b/Library/Homebrew/cask/lib/hbc/audit.rb
@@ -31,6 +31,7 @@ module Hbc
check_generic_artifacts
check_token_conflicts
check_download
+ check_single_pre_postflight
check_single_uninstall_zap
self
rescue StandardError => e
@@ -49,20 +50,24 @@ module Hbc
private
+ def check_single_pre_postflight
+ odebug "Auditing preflight and postflight stanzas"
+
+ add_warning "only a single preflight stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PreflightBlock) && k.directives.key?(:preflight) } > 1
+
+ add_warning "only a single postflight stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PostflightBlock) && k.directives.key?(:postflight) } > 1
+ end
+
def check_single_uninstall_zap
odebug "Auditing single uninstall_* and zap stanzas"
- uninstalls = cask.artifacts.find_all { |k| k.is_a?(Hbc::Artifact::Uninstall) }
- add_warning "there should be a single uninstall stanza" unless uninstalls.size <= 1
+ add_warning "only a single uninstall stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::Uninstall) } > 1
- uninstalls_preflight = cask.artifacts.find_all { |k| k.is_a?(Hbc::Artifact::PreflightBlock) && k.directives.keys.include?("uninstall_preflight") }
- add_warning "there should be a single uninstall_preflight stanza" unless uninstalls_preflight.size <= 1
+ add_warning "only a single uninstall_preflight stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PreflightBlock) && k.directives.key?(:uninstall_preflight) } > 1
- uninstalls_postflight = cask.artifacts.find_all { |k| k.is_a?(Hbc::Artifact::PostflightBlock) && k.directives.keys.include?("uninstall_postflight") }
- add_warning "there should be a single uninstall_postflight stanza" unless uninstalls_postflight.size <= 1
+ add_warning "only a single uninstall_postflight stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PostflightBlock) && k.directives.key?(:uninstall_postflight) } > 1
- zaps = cask.artifacts.find_all { |k| k.is_a?(Hbc::Artifact::Zap) }
- add_warning "there should be a single zap stanza" unless zaps.size <= 1
+ add_warning "only a single zap stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::Zap) } > 1
end
def check_required_stanzas