Over a million developers have joined DZone.

Reek Rake Task

DZone's Guide to

Reek Rake Task

Free Resource
This will use the Reek Ruby Gem and Rake to go through your Rails app and call Reek on every .rb file.  It pipes the Reek output to a file in public/reek/file_name.rb.txt and generates an index.html file in public/reek/ with links to view each text file.  I wrote this Rake task because I couldn't seem to run Reek on my Rails app's app/ directory; maybe I just didn't read enough about Reek's usage.

Save this file with the extension .rake in your Rails app's lib/tasks/ directory, e.g. lib/tasks/reek.rake.  You can then run 'rake reek' on the command line within your Rails app's directory.  You will need Reek to be installed first, and Reek should be runnable just by typing 'reek'.

desc "Will generate Reek output for each Ruby file in RAILS_ROOT."
task(:reek) do
  require 'find'
  require 'fileutils'
  reek_dir_name = "reek"
  reek_dir = "#{RAILS_ROOT}/public/#{reek_dir_name}"
  index_file = "#{reek_dir}/index.html"
  output_files = {}
  unless File.exists?(reek_dir) && File.directory?(reek_dir)
  Find.find(RAILS_ROOT) do |path|
    if path =~ /\.rb$/i
      output_file = "#{File.basename(path)}.txt"
      cmd = "reek #{path} > #{reek_dir}/#{output_file}"
      puts cmd
      output_files[path] = output_file
  puts "Writing index file to #{index_file}..."
  File.open(index_file, 'w') do |file|
    file.write('Reek Results')
    ') output_files.each do |path, name| next unless File.size?(path) file.write('
  1. ') file.write('' + name + '') file.write(' (' + path + ')') file.write(' file size ' + File.size(path).to_s) file.write('
  2. ') end file.write('
') file.write('') file.write('') end end

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}