class SugarCane::RakeTask
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
Attributes
name[RW]
options[R]
Public Class Methods
new(task_name = nil) { |self| ... }
click to toggle source
# File lib/sugarcane/rake_task.rb, line 52 def initialize(task_name = nil) self.name = task_name || :cane @gte = [] @options = SugarCane::CLI.default_options @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(options) end end
Public Instance Methods
add_threshold(file, operator, value)
click to toggle source
Add a threshold check. If the file exists and it contains a number, compare that number with the given value using the operator.
# File lib/sugarcane/rake_task.rb, line 35 def add_threshold(file, operator, value) if operator == :>= @options[:gte] << [file, value] end end
canefile=(file)
click to toggle source
# File lib/sugarcane/rake_task.rb, line 46 def canefile=(file) canefile = SugarCane::CLI::Parser.new canefile.parser.parse!(canefile.read_options_from_file(file)) options.merge! canefile.options end
use(check, options = {})
click to toggle source
# File lib/sugarcane/rake_task.rb, line 41 def use(check, options = {}) @options.merge!(options) @options[:checks] = @options[:checks] + [check] end