Reek Rake Task
Join the DZone community and get the full member experience.
Join For FreeThis 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)
FileUtils.mkdir(reek_dir)
end
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
system(cmd)
output_files[path] = output_file
end
end
puts "Writing index file to #{index_file}..."
File.open(index_file, 'w') do |file|
file.write('')
file.write('')
file.write('Reek Results ')
file.write('')
file.write('')
file.write('')
output_files.each do |path, name|
next unless File.size?(path)
file.write('- ')
file.write('' + name + '')
file.write(' (' + path + ')')
file.write(' file size ' + File.size(path).to_s)
file.write('
')
end
file.write('
')
file.write('')
file.write('')
end
end
Task (computing)
Opinions expressed by DZone contributors are their own.
Comments