class Reek::Rake::Task
A Rake
task that runs Reek
on a set of source files.
Example:
require 'reek/rake/task' Reek::Rake::Task.new do |t| t.fail_on_error = false end
This will create a task that can be run with:
rake reek
Examples:
rake reek # checks lib/**/*.rb rake reek REEK_SRC=just_one_file.rb # checks a single source file rake reek REEK_OPTS=-s # sorts the report by smell
@public
@quality :reek:TooManyInstanceVariables { max_instance_variables: 6 } @quality :reek:Attribute
Attributes
Path to Reek’s config file. Setting the REEK_CFG environment variable overrides this. @public
Whether or not to fail Rake
when an error occurs (typically when smells are found). Defaults to true. @public
String containing commandline options to be passed to Reek
. Setting the REEK_OPTS environment variable overrides this value. Defaults to ”. @public
Glob pattern to match source files. Setting the REEK_SRC environment variable overrides this. Defaults to ‘lib/*/.rb’. @public
Use verbose output. If this is set to true, the task will print the reek command to stdout. Defaults to false. @public
Public Class Methods
Source
# File lib/reek/rake/task.rb, line 71 def initialize(name = :reek) @config_file = ENV.fetch('REEK_CFG', nil) @name = name @reek_opts = ENV.fetch('REEK_OPTS', '') @fail_on_error = true @verbose = false yield self if block_given? if (reek_src = ENV.fetch('REEK_SRC', nil)) @source_files = FileList[reek_src] end @source_files ||= FileList['lib/**/*.rb'] define_task end
@public
Public Instance Methods
Source
# File lib/reek/rake/task.rb, line 88 def source_files=(files) unless files.is_a?(String) || files.is_a?(FileList) raise ArgumentError, 'File list should be a FileList or a String that can contain ' \ "a glob pattern, e.g. '{app,lib,spec}/**/*.rb'" end @source_files = FileList[files] end
@public
Private Instance Methods
Source
# File lib/reek/rake/task.rb, line 111 def command ['reek', *config_file_as_argument, *reek_opts_as_arguments, *source_files]. compact. reject(&:empty?) end
Source
# File lib/reek/rake/task.rb, line 122 def config_file_as_argument config_file ? ['-c', config_file] : [] end
Source
# File lib/reek/rake/task.rb, line 100 def define_task desc 'Check for code smells' task(name) { run_task } end
Source
# File lib/reek/rake/task.rb, line 126 def reek_opts_as_arguments reek_opts.split(/\s+/) end
Source
# File lib/reek/rake/task.rb, line 105 def run_task puts "\n\n!!! Running 'reek' rake command: #{command}\n\n" if verbose system(*command) abort("\n\n!!! Reek has found smells - exiting!") if sys_call_failed? && fail_on_error end
Source
# File lib/reek/rake/task.rb, line 118 def sys_call_failed? !$CHILD_STATUS.success? end
@quality :reek:UtilityFunction