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,
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 ⇒ YARD::CLI::Yardoc 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
)
69 70 71 72 73 74 75 76 77 |
# File 'lib/kamaze/project/tools/rubocop.rb', line 69 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
46 47 48 |
# File 'lib/kamaze/project/tools/rubocop.rb', line 46 def defaults @defaults end |
#observer_peers ⇒ Hash|nil (readonly, protected) Originally defined in module Concern::Observable
Instance Method Details
#core ⇒ YARD::CLI::Yardoc (protected)
124 125 126 127 128 |
# File 'lib/kamaze/project/tools/rubocop.rb', line 124 def core require 'rubocop' RuboCop::CLI.new end |
#failure? ⇒ Boolean Also known as: failed? Originally defined in module Concern::Cli
Denote execution is a failure.
#mutable_attributes ⇒ Object
48 49 50 |
# File 'lib/kamaze/project/tools/rubocop.rb', line 48 def mutable_attributes [:defaults] end |
#prepare ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/kamaze/project/tools/rubocop.rb', line 52 def prepare reset if block_given? config = Config.new yield(config) arguments.concat(config.freeze.to_a) end arguments.freeze self end |
#reset ⇒ self (protected)
Reset arguments + retcode
116 117 118 119 120 121 |
# File 'lib/kamaze/project/tools/rubocop.rb', line 116 def reset @arguments = nil self.retcode = nil if retcode.to_i.zero? self end |
#retcode ⇒ Fixnum Originally defined in module Concern::Cli
Status code usable to eventually initiates the termination.
#run ⇒ self
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/kamaze/project/tools/rubocop.rb', line 90 def run prepare if arguments.to_a.empty? if runnable? with_exit_on_failure do core.run(arguments.to_a).yield_self do |retcode| self.retcode = retcode reset end end end self end |
#runnable? ⇒ Boolean
Denote runnable
When last argument is --
we suppose there is no files
84 85 86 |
# File 'lib/kamaze/project/tools/rubocop.rb', line 84 def runnable? '--' != arguments.last end |
#setup ⇒ Object (protected)
109 110 111 |
# File 'lib/kamaze/project/tools/rubocop.rb', line 109 def setup @defaults = Arguments.new(@defaults.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.