From dcbcf167f69dd6b5a4039a8488091b18d61b5b79 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 6 Mar 2017 18:18:04 +0100 Subject: [PATCH] Refactor `brew cask _audit_modified_casks`. --- .../hbc/cli/internal_audit_modified_casks.rb | 63 +++++++++---------- 1 file changed, 28 insertions(+), 35 deletions(-) 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 d750f5af4d..3b46bffe4a 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 @@ -3,40 +3,38 @@ module Hbc class InternalAuditModifiedCasks < InternalUseBase RELEVANT_STANZAS = [:version, :sha256, :url, :appcast].freeze - class << self - def needs_init? - true - end + def self.needs_init? + true + end - def run(*args) - commit_range = commit_range(args) - cleanup = args.any? { |a| a =~ /^-+c(leanup)?$/i } - new(commit_range, cleanup: cleanup).run - end + def self.run(*args) + commit_range = commit_range(args) + cleanup = args.any? { |a| a =~ /^-+c(leanup)?$/i } + new(commit_range, cleanup: cleanup).run + end - def commit_range(args) - posargs = args.reject { |a| a.empty? || a.chars.first == "-" } - odie usage unless posargs.size == 1 - posargs.first - end + def self.commit_range(args) + posargs = args.reject { |a| a.empty? || a.chars.first == "-" } + odie usage unless posargs.size == 1 + posargs.first + end - def posargs(args) - args.reject { |a| a.empty? || a.chars.first == "-" } - end + def self.posargs(args) + args.reject { |a| a.empty? || a.chars.first == "-" } + end - def usage - <<-EOS.undent - Usage: brew cask _audit_modified_casks [options...] + def self.usage + <<-EOS.undent + Usage: brew cask _audit_modified_casks [options...] - Given a range of Git commits, find any Casks that were modified and run `brew - cask audit' on them. If the `url', `version', or `sha256' stanzas were modified, - run with the `--download' flag to verify the hash. + Given a range of Git commits, find any Casks that were modified and run `brew + cask audit' on them. If the `url', `version', or `sha256' stanzas were modified, + run with the `--download' flag to verify the hash. - Options: - -c, --cleanup - Remove all cached downloads. Use with care. - EOS - end + Options: + -c, --cleanup + Remove all cached downloads. Use with care. + EOS end def initialize(commit_range, cleanup: false) @@ -85,7 +83,7 @@ module Hbc @modified_casks = modified_cask_files.map { |f| Hbc.load(f) } if @modified_casks.any? num_modified = @modified_casks.size - ohai "#{num_modified} modified #{pluralize("cask", num_modified)}: " \ + ohai "#{num_modified} modified cask#{plural(num_modified)}: " \ "#{@modified_casks.join(" ")}" end @modified_casks @@ -122,15 +120,10 @@ module Hbc def report_failures return if failed_casks.empty? num_failed = failed_casks.size - cask_pluralized = pluralize("cask", num_failed) - odie "audit failed for #{num_failed} #{cask_pluralized}: " \ + odie "audit failed for #{num_failed} cask#{plural(num_failed)}: " \ "#{failed_casks.join(" ")}" end - def pluralize(str, num) - num == 1 ? str : "#{str}s" - end - def cleanup Cleanup.run if cleanup? end