class RubyCritic::RakeTask

A rake task that runs RubyCritic on a set of source files.

This will create a task that can be run with:

rake rubycritic

Example:

require 'rubycritic/rake_task'

RubyCritic::RakeTask.new do |task|
  task.paths = FileList['lib/**/*.rb', 'spec/**/*.rb']
end

Attributes

description[R]
fail_on_error[RW]

Whether or not to fail Rake task when RubyCritic does not pass. Defaults to true.

name[RW]

Name of RubyCritic task. Defaults to :rubycritic.

options[RW]

You can pass all the options here in that are shown by “rubycritic -h” except for “-p / –path” since that is set separately. Defaults to ”.

paths[RW]

Glob pattern to match source files. Defaults to FileList.

verbose[RW]

Use verbose output. If this is set to true, the task will print the rubycritic command to stdout. Defaults to false.

Public Class Methods

new(name = :rubycritic, description = 'Run RubyCritic') { |self| ... } click to toggle source
# File lib/rubycritic/rake_task.rb, line 43
def initialize(name = :rubycritic, description = 'Run RubyCritic')
  @name           = name
  @description    = description
  @paths          = FileList['.']
  @options        = ''
  @verbose        = false
  @fail_on_error  = true

  yield self if block_given?
  define_task
end

Private Instance Methods

define_task() click to toggle source
# File lib/rubycritic/rake_task.rb, line 59
def define_task
  desc description
  task(name) { run_task }
end
options_as_arguments() click to toggle source
# File lib/rubycritic/rake_task.rb, line 77
def options_as_arguments
  options.split(/\s+/)
end
print_starting_up_output() click to toggle source
run_task() click to toggle source
# File lib/rubycritic/rake_task.rb, line 64
def run_task
  print_starting_up_output if verbose
  application = RubyCritic::Cli::Application.new(options_as_arguments + paths)
  return unless application.execute.nonzero? && fail_on_error

  abort('RubyCritic did not pass - exiting!')
end