Class: Reek::Rake::Task

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/reek/rake/task.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :reek) {|_self| ... } ⇒ Task

Returns a new instance of Task.

Yields:

  • (_self)

Yield Parameters:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# 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

Instance Attribute Details

#config_fileObject

Path to Reek’s config file. Setting the REEK_CFG environment variable overrides this.



46
47
48
# File 'lib/reek/rake/task.rb', line 46

def config_file
  @config_file
end

#fail_on_errorObject (private)

Returns the value of attribute fail_on_error.



98
99
100
# File 'lib/reek/rake/task.rb', line 98

def fail_on_error
  @fail_on_error
end

#nameObject (private)

Returns the value of attribute name.



98
99
100
# File 'lib/reek/rake/task.rb', line 98

def name
  @name
end

#reek_optsObject

String containing commandline options to be passed to Reek. Setting the REEK_OPTS environment variable overrides this value. Defaults to ”.



58
59
60
# File 'lib/reek/rake/task.rb', line 58

def reek_opts
  @reek_opts
end

#source_filesObject

Glob pattern to match source files. Setting the REEK_SRC environment variable overrides this. Defaults to ‘lib/*/.rb’.



52
53
54
# File 'lib/reek/rake/task.rb', line 52

def source_files
  @source_files
end

#verboseObject (private)

Returns the value of attribute verbose.



98
99
100
# File 'lib/reek/rake/task.rb', line 98

def verbose
  @verbose
end

Instance Method Details

#commandObject (private)



111
112
113
114
115
# 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

#config_file_as_argumentObject (private)



122
123
124
# File 'lib/reek/rake/task.rb', line 122

def config_file_as_argument
  config_file ? ['-c', config_file] : []
end

#define_taskObject (private)



100
101
102
103
# File 'lib/reek/rake/task.rb', line 100

def define_task
  desc 'Check for code smells'
  task(name) { run_task }
end

#reek_opts_as_argumentsObject (private)



126
127
128
# File 'lib/reek/rake/task.rb', line 126

def reek_opts_as_arguments
  reek_opts.split(/\s+/)
end

#run_taskObject (private)



105
106
107
108
109
# 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

#sys_call_failed?Boolean (private)

Returns:

  • (Boolean)


118
119
120
# File 'lib/reek/rake/task.rb', line 118

def sys_call_failed?
  !$CHILD_STATUS.success?
end