DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone >

Reek Rake Task

Snippets Manager user avatar by
Snippets Manager
·
Mar. 30, 09 · · Code Snippet
Like (0)
Save
Tweet
507 Views

Join the DZone community and get the full member experience.

Join For Free
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)
    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('
  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
Task (computing)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 5 Steps to Strengthen API Security
  • The Evolution of Configuration Management: IaC vs. GitOps
  • Evolving Domain-Specific Languages
  • How to Utilize Python Machine Learning Models

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo