Rails Refactor & Hack Night

During the RORO hack night last Wednesday, Ryan Bigg (@ryanbigg) and I worked on a Rails Refactor, something I've been meaning to get going for a long time.

How often have you wasted time doing renames in rails? Sure it's hard to automate everything without understanding the code, but there sure are a lot of mechanical steps that you can easily automate. Ryan and I took on controller renames and got a fair way in the few hours we spent on the night.

Code is on github

To rename a controller:
$ rails_refactor.rb rename OldController NewController

  • renames controller file & class name in file
  • renames controller spec file & class name in file
  • renames view directory
  • renames helper file & module name in file
  • updates routes

To rename a controller action:
$ rails_refactor.rb rename DummyController.old_action new_action

  • renames controller action in controller class file
  • renames view files for all formats

Looking to extend it with model renames, and then more complex refactoring.
If you like it, please fork and contribute 🙂


Actions

Information

2 responses to “Rails Refactor & Hack Night”

27 11 2010
Chris Kimpton (20:01:55) :

Have you seen RubyMine - http://www.jetbrains.com/ruby/

I appreciate its not free - but it does have some refactorings like this already.

~chris

19 05 2013
Johnny (20:39:33) :

Nice post! The gem is quite quite useful! Thanks a lot.