Class: Kamaze::Project::Tools::Rubocop
- Inherits:
-
BaseTool
- Object
- Observable
- BaseTool
- Kamaze::Project::Tools::Rubocop
- Includes:
- Concern::Cli::WithExitOnFailure
- Defined in:
- lib/kamaze/project/tools/rubocop.rb
Overview
Tool to run Rubocop::CLI
Sample of use:
Rubocop.new.prepare do |c|
c.patterns = ["#{Dir.pwd}/test/cs.rb"]
c. = ['--fail-level', 'E']
end.run
Defined Under Namespace
Instance Attribute Summary collapse
-
#arguments ⇒ Arguments
Arguments used by
CLI
(during execution/run
). -
#defaults ⇒ Arguments
Default arguments used by
Rubocop::CLI
. - #observer_peers ⇒ Hash|nil included from Concern::Observable readonly protected
Instance Method Summary collapse
- #core ⇒ RuboCop::CLI protected
-
#failure? ⇒ Boolean
(also: #failed?)
included
from Concern::Cli
Denote execution is a failure.
- #mutable_attributes ⇒ Object
- #prepare ⇒ Object
-
#reset ⇒ self
protected
Reset arguments + retcode.
-
#retcode ⇒ Fixnum
included
from Concern::Cli
Status code usable to eventually initiates the termination.
- #run ⇒ self
-
#runnable? ⇒ Boolean
Denote runnable.
- #setup ⇒ Object protected
-
#success? ⇒ Boolean
(also: #successful?)
included
from Concern::Cli
Denote execution is a success.
-
#with_exit_on_failure {|Object| ... } ⇒ Object
included
from Concern::Cli::WithExitOnFailure
protected
Initiates termination by raising
SystemExit
exception depending onsuccess
of given block.
Constructor Details
This class inherits a constructor from Kamaze::Project::Tools::BaseTool
Instance Attribute Details
#arguments ⇒ Arguments
Arguments used by CLI
(during execution/run
)
62 63 64 65 66 67 68 69 70 |
# 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 |
#defaults ⇒ Arguments
Default arguments used by Rubocop::CLI
38 39 40 |
# File 'lib/kamaze/project/tools/rubocop.rb', line 38 def defaults @defaults end |
#observer_peers ⇒ Hash|nil (readonly, protected) Originally defined in module Concern::Observable
Instance Method Details
#core ⇒ RuboCop::CLI (protected)
115 116 117 |
# File 'lib/kamaze/project/tools/rubocop.rb', line 115 def core RuboCop::CLI.new end |
#failure? ⇒ Boolean Also known as: failed? Originally defined in module Concern::Cli
Denote execution is a failure.
#mutable_attributes ⇒ Object
40 41 42 |
# File 'lib/kamaze/project/tools/rubocop.rb', line 40 def mutable_attributes [:defaults] end |
#prepare ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# 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 |
#reset ⇒ self (protected)
Reset arguments + retcode
107 108 109 110 111 112 |
# 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 |
#retcode ⇒ Fixnum Originally defined in module Concern::Cli
Status code usable to eventually initiates the termination.
#run ⇒ self
83 84 85 86 87 88 89 90 91 92 93 94 |
# 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? ⇒ Boolean
Denote runnable
When last argument is --
we suppose there is no files
77 78 79 |
# File 'lib/kamaze/project/tools/rubocop.rb', line 77 def runnable? '--' != arguments.last end |
#setup ⇒ Object (protected)
100 101 102 |
# File 'lib/kamaze/project/tools/rubocop.rb', line 100 def setup @defaults = Arguments.new((@defaults || ['--only-recognized-file-types']).to_a) end |
#success? ⇒ Boolean Also known as: successful? Originally defined in module Concern::Cli
Denote execution is a success.
#with_exit_on_failure {|Object| ... } ⇒ Object (protected) Originally defined in module Concern::Cli::WithExitOnFailure
Initiates termination by raising SystemExit
exception
depending on success
of given block.