Class: SugarCane::RakeTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- SugarCane::RakeTask
- Defined in:
- lib/sugarcane/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
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#add_threshold(file, operator, value) ⇒ Object
Add a threshold check.
- #canefile=(file) ⇒ Object
-
#initialize(task_name = nil) ⇒ RakeTask
constructor
A new instance of RakeTask.
- #use(check, options = {}) ⇒ Object
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 72 73 74 75 76 |
# File 'lib/sugarcane/rake_task.rb', line 52 def initialize(task_name = nil) self.name = task_name || :cane @gte = [] @options = SugarCane::CLI. @options[:report] = true if block_given? yield self else if File.exists?('./sugarcane') self.canefile = './.sugarcane' else self.canefile = './.cane' end end unless ::Rake.application.last_comment desc %(Check code quality metrics with cane) end task name do require 'sugarcane/cli' abort unless SugarCane.run() end end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
20 21 22 |
# File 'lib/sugarcane/rake_task.rb', line 20 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
21 22 23 |
# File 'lib/sugarcane/rake_task.rb', line 21 def @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/sugarcane/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/sugarcane/rake_task.rb', line 46 def canefile=(file) canefile = SugarCane::CLI::Parser.new canefile.parser.parse!(canefile.(file)) .merge! canefile. end |
#use(check, options = {}) ⇒ Object
41 42 43 44 |
# File 'lib/sugarcane/rake_task.rb', line 41 def use(check, = {}) @options.merge!() @options[:checks] = @options[:checks] + [check] end |