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

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) { |self| ... } click to toggle source
# File lib/rubycritic/rake_task.rb, line 39
def initialize(name = :rubycritic)
  @name    = name
  @paths   = FileList['.']
  @options = ''
  @verbose = false

  yield self if block_given?
  define_task
end

Private Instance Methods

define_task() click to toggle source
# File lib/rubycritic/rake_task.rb, line 53
def define_task
  desc 'Run RubyCritic'
  task(name) { run_task }
end
options_as_arguments() click to toggle source
# File lib/rubycritic/rake_task.rb, line 67
def options_as_arguments
  options.split(/\s+/)
end
run_task() click to toggle source
# File lib/rubycritic/rake_task.rb, line 58
def run_task
  if verbose
    puts "\n\n!!! Running `#{name}` rake command\n"
    puts "!!! Inspecting #{paths} #{options.empty? ? '' : "with options #{options}"}\n\n"
  end
  application = RubyCritic::Cli::Application.new(options_as_arguments + paths)
  application.execute
end