From cac0c29f732f2de3362b353b8f86e345469397ff Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 20 May 2017 02:57:37 +0200 Subject: [PATCH] Refactor `CLI::InternalDump`. --- .../cask/lib/hbc/cli/internal_dump.rb | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb index 94dd309bdb..e6dc3510ff 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb @@ -1,19 +1,26 @@ module Hbc class CLI class InternalDump < InternalUseBase - def self.run(*arguments) - cask_tokens = cask_tokens_from(arguments) - raise CaskUnspecifiedError if cask_tokens.empty? - retval = dump_casks(*cask_tokens) + def self.run(*args) + new(*args).run + end + + def initialize(*args) + @cask_tokens = self.class.cask_tokens_from(args) + raise CaskUnspecifiedError if @cask_tokens.empty? + end + + def run + retval = dump_casks # retval is ternary: true/false/nil raise CaskError, "nothing to dump" if retval.nil? raise CaskError, "dump incomplete" unless retval end - def self.dump_casks(*cask_tokens) + def dump_casks count = 0 - cask_tokens.each do |cask_token| + @cask_tokens.each do |cask_token| begin cask = CaskLoader.load(cask_token) count += 1 @@ -22,7 +29,7 @@ module Hbc opoo "#{cask_token} was not found or would not load: #{e}" end end - count.zero? ? nil : count == cask_tokens.length + count.zero? ? nil : count == @cask_tokens.length end def self.help