aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib
diff options
context:
space:
mode:
authorMarkus Reiter2017-05-20 03:46:52 +0200
committerMarkus Reiter2017-05-22 02:51:16 +0200
commit98f91fb88331ee1bc5f190fec827048a38bf8498 (patch)
tree60848483072e1800c835991e55f81a7af1b0a45d /Library/Homebrew/cask/lib
parent957c5fb4f0f690ed82b8a6a38ec106f4784a9ed9 (diff)
downloadbrew-98f91fb88331ee1bc5f190fec827048a38bf8498.tar.bz2
Refactor `CLI::Style`.
Diffstat (limited to 'Library/Homebrew/cask/lib')
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/style.rb31
1 files changed, 14 insertions, 17 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cli/style.rb b/Library/Homebrew/cask/lib/hbc/cli/style.rb
index 191aefd3c..a76c893fc 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/style.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/style.rb
@@ -8,19 +8,24 @@ module Hbc
end
def self.run(*args)
- retval = new(args).run
- raise CaskError, "style check failed" unless retval
+ new(*args).run
end
attr_reader :args
- def initialize(args)
- @args = args
+ def initialize(*args)
+ @cask_tokens = self.class.cask_tokens_from(args)
+ @fix = args.any? { |arg| arg =~ /^--(fix|(auto-?)?correct)$/ }
+ end
+
+ def fix?
+ @fix
end
def run
install_rubocop
system "rubocop", *rubocop_args, "--", *cask_paths
- $CHILD_STATUS.success?
+ raise CaskError, "style check failed" unless $CHILD_STATUS.success?
+ true
end
def install_rubocop
@@ -34,19 +39,15 @@ module Hbc
end
def cask_paths
- @cask_paths ||= if cask_tokens.empty?
+ @cask_paths ||= if @cask_tokens.empty?
Hbc.all_tapped_cask_dirs
- elsif cask_tokens.any? { |file| File.exist?(file) }
- cask_tokens
+ elsif @cask_tokens.any? { |file| File.exist?(file) }
+ @cask_tokens
else
- cask_tokens.map { |token| CaskLoader.path(token) }
+ @cask_tokens.map { |token| CaskLoader.path(token) }
end
end
- def cask_tokens
- @cask_tokens ||= self.class.cask_tokens_from(args)
- end
-
def rubocop_args
fix? ? autocorrect_args : default_args
end
@@ -63,10 +64,6 @@ module Hbc
def autocorrect_args
default_args + ["--auto-correct"]
end
-
- def fix?
- args.any? { |arg| arg =~ /--(fix|(auto-?)?correct)/ }
- end
end
end
end