Class: Cane::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/cane/rake_task.rb

Overview

Creates a rake task to run cane with given configuration.

Examples

desc "Run code quality checks"
Cane::RakeTask.new(:quality) do |cane|
  cane.abc_max = 10
  cane.doc_glob = 'lib/**/*.rb'
  cane.no_style = true
  cane.add_threshold 'coverage/covered_percent', :>=, 99
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task_name = nil) {|_self| ... } ⇒ RakeTask

Returns a new instance of RakeTask.

Yields:

  • (_self)

Yield Parameters:



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cane/rake_task.rb', line 42

def initialize(task_name = nil)
  self.name = task_name || :cane
  @threshold = []
  yield self if block_given?

  unless ::Rake.application.last_comment
    desc %(Check code quality metrics with cane)
  end

  task name do
    require 'cane/cli'
    abort unless Cane.run(translated_options)
  end
end

Instance Attribute Details

#abc_globObject

Glob to run ABC metrics over (default: “lib/*/.rb”)



20
21
22
# File 'lib/cane/rake_task.rb', line 20

def abc_glob
  @abc_glob
end

#abc_maxObject

Max complexity of methods to allow (default: 15)



22
23
24
# File 'lib/cane/rake_task.rb', line 22

def abc_max
  @abc_max
end

#doc_globObject

Glob to run doc checks over (default: “lib/*/.rb”)



30
31
32
# File 'lib/cane/rake_task.rb', line 30

def doc_glob
  @doc_glob
end

#max_violationsObject

Max violations to tolerate (default: 0)



34
35
36
# File 'lib/cane/rake_task.rb', line 34

def max_violations
  @max_violations
end

#nameObject

Returns the value of attribute name.



17
18
19
# File 'lib/cane/rake_task.rb', line 17

def name
  @name
end

#no_docObject

TRUE to disable doc checks



32
33
34
# File 'lib/cane/rake_task.rb', line 32

def no_doc
  @no_doc
end

#no_styleObject

TRUE to disable style checks



26
27
28
# File 'lib/cane/rake_task.rb', line 26

def no_style
  @no_style
end

#style_globObject

Glob to run style checks over (default: “lib,spec/*/.rb”)



24
25
26
# File 'lib/cane/rake_task.rb', line 24

def style_glob
  @style_glob
end

#style_measureObject

Max line length (default: 80)



28
29
30
# File 'lib/cane/rake_task.rb', line 28

def style_measure
  @style_measure
end

Instance Method Details

#add_threshold(file, operator, value) ⇒ Object

Add a threshold check. If the file exists and it contains a number, compare that number with the given value using the operator.



38
39
40
# File 'lib/cane/rake_task.rb', line 38

def add_threshold(file, operator, value)
  @threshold << [operator, file, value]
end

#default_optionsObject



74
75
76
# File 'lib/cane/rake_task.rb', line 74

def default_options
  Cane::CLI::Spec::DEFAULTS
end

#optionsObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/cane/rake_task.rb', line 57

def options
  [
    :abc_glob,
    :abc_max,
    :doc_glob,
    :no_doc,
    :max_violations,
    :style_glob,
    :no_style,
    :style_measure
  ].inject(threshold: @threshold) do |opts, setting|
    value = self.send(setting)
    opts[setting] = value unless value.nil?
    opts
  end
end

#translated_optionsObject



78
79
80
# File 'lib/cane/rake_task.rb', line 78

def translated_options
  Cane::CLI::Translator.new(options, default_options).to_hash
end