class Kamaze::Project::Tools::Rubocop
Tool to run “Rubocop::CLI“
Sample of use:
“`ruby Rubocop.new
.prepare do |c|
c.patterns = ["#{Dir.pwd}/test/cs.rb"] c.options = ['--fail-level', 'E']
end.run “`
Attributes
arguments[W]
defaults[RW]
Default arguments used by “Rubocop::CLI“
@type [Array|Arguments] @return [Arguments]
Public Instance Methods
arguments()
click to toggle source
Arguments
used by “CLI“ (during execution/“run“)
@return [Arguments]
# File lib/kamaze/project/tools/rubocop.rb, line 62 def arguments @arguments = defaults.clone if @arguments.to_a.size.zero? if caller_locations(1..1).first.path == __FILE__ @arguments else @arguments.clone.freeze end end
mutable_attributes()
click to toggle source
# File lib/kamaze/project/tools/rubocop.rb, line 40 def mutable_attributes [:defaults] end
prepare() { |config| ... }
click to toggle source
# File lib/kamaze/project/tools/rubocop.rb, line 44 def prepare self.tap do reset if block_given? Config.new.tap do |config| yield(config) arguments.concat(config.freeze.to_a) end end arguments.freeze end end
run()
click to toggle source
@raise [SystemExit] @return [self]
# File lib/kamaze/project/tools/rubocop.rb, line 83 def run prepare if arguments.to_a.empty? if runnable? with_exit_on_failure do core.run(arguments.to_a).tap { |retcode| self.retcode = retcode } reset end end self end
runnable?()
click to toggle source
Denote runnable
When last argument is “–“ we suppose there is no files
@return [Boolean]
# File lib/kamaze/project/tools/rubocop.rb, line 77 def runnable? '--' != arguments.last end
Protected Instance Methods
core()
click to toggle source
@return [RuboCop::CLI]
# File lib/kamaze/project/tools/rubocop.rb, line 115 def core RuboCop::CLI.new end
reset()
click to toggle source
Reset arguments + retcode
@return [self]
# File lib/kamaze/project/tools/rubocop.rb, line 107 def reset self.tap do @arguments = nil self.retcode = nil if retcode.to_i.zero? end end
setup()
click to toggle source
# File lib/kamaze/project/tools/rubocop.rb, line 100 def setup @defaults = Arguments.new((@defaults || ['--only-recognized-file-types']).to_a) end