/rails_deadweight

[DEPRECATED] A tool for finding unused code in your Rails application

Primary LanguageRubyOtherNOASSERTION

Rails Deadweight

Rails Deadweight (RD) is a simple tool that facilitates easy pruning of unused code in a Rails project. RD is great for dealing with legacy Rails codebases that need some love.

RD finds all the classes and methods defined in your Rails project and then outputs a list of the ones that are not used anywhere. It takes into account classes and methods that are defined in your ‘lib’ folder as well as your ‘app’ folder and is smart enough to map routes to controllers and methods as well, minimizing the number of false positives.

Installation

For convenience Rails Deadweight is packaged as a RubyGem. Installation is as simple as:

gem install rails_deadweight

Usage

Simply cd to the root folder of your Rails app, then run rails_deadweight like so:

cd /path/to/rails/app
rails_deadweight

RD will then process your rails projects and output a report listing all the classes and methods that it considers ‘dead weight’, and where they can be found in the project so you can delete them.

Usage Notes

The best way to use Rails Deadweight is to run it against your application the same way you would run your test suite: run rails_deadweight, remove a section of the unused code, run your tests, get them to pass, commit, and then start again.

Trying to remove everything that Rails Deadweight finds in one go is not advisable, because if you run up against test failures it will be very difficult to find out which part of your change caused the failure. Rails Deadweight does its best to minimize false positives, but because of the highly dynamic nature of Ruby you are likely to get at least a few false positives in large projects. Double-check each class or method before you delete it, and make sure you run your tests often!

Have fun deleting some code!

Contributors

Contributors

Aaron Gough