Class: Kamaze::Project::Tools::Rubocop

Inherits:
BaseTool show all
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.options = ['--fail-level', 'E']
end.run

Defined Under Namespace

Classes: Arguments, Config

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Kamaze::Project::Tools::BaseTool

Instance Attribute Details

#argumentsArguments

Arguments used by CLI (during execution/run)

Returns:



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

#defaultsArguments

Default arguments used by Rubocop::CLI

Returns:



46
47
48
# File 'lib/kamaze/project/tools/rubocop.rb', line 46

def defaults
  @defaults
end

#observer_peersHash|nil (readonly, protected) Originally defined in module Concern::Observable

Returns:

  • (Hash|nil)

Instance Method Details

#coreYARD::CLI::Yardoc (protected)

Returns:

  • (YARD::CLI::Yardoc)


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.

Returns:

  • (Boolean)

#mutable_attributesObject



48
49
50
# File 'lib/kamaze/project/tools/rubocop.rb', line 48

def mutable_attributes
  [:defaults]
end

#prepareObject



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

#resetself (protected)

Reset arguments + retcode

Returns:

  • (self)


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

#retcodeFixnum Originally defined in module Concern::Cli

Status code usable to eventually initiates the termination.

Returns:

  • (Fixnum)

#runself

Returns:

  • (self)

Raises:

  • (SystemExit)


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

Returns:

  • (Boolean)


84
85
86
# File 'lib/kamaze/project/tools/rubocop.rb', line 84

def runnable?
  '--' != arguments.last
end

#setupObject (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.

Returns:

  • (Boolean)

#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.

Yields:

Yield Parameters:

  • (self)

Returns:

Raises:

  • (SystemExit)