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) ⇒ RakeTask

Returns a new instance of RakeTask.


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

def initialize(task_name = nil)
  self.name = task_name || :cane
  @gte = []
  @options = Cane::CLI.default_options

  if block_given?
    yield self
  else
    self.canefile = './.cane'
  end

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

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

Instance Attribute Details

#nameObject

Returns the value of attribute name


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

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options


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

def options
  @options
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.


35
36
37
38
39
# File 'lib/cane/rake_task.rb', line 35

def add_threshold(file, operator, value)
  if operator == :>=
    @options[:gte] << [file, value]
  end
end

#canefile=(file) ⇒ Object


46
47
48
49
50
# File 'lib/cane/rake_task.rb', line 46

def canefile=(file)
  canefile = Cane::CLI::Parser.new
  canefile.parser.parse!(canefile.read_options_from_file(file))
  options.merge! canefile.options
end

#use(check, options = {}) ⇒ Object


41
42
43
44
# File 'lib/cane/rake_task.rb', line 41

def use(check, options = {})
  @options.merge!(options)
  @options[:checks] = @options[:checks] + [check]
end