Software dev, tech, mind hacks and the occasional personal bit

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 🙂

Previous

Odd Date and Time Comparisons in Rails & Hack night

Next

nRake Microsoft Case Study

2 Comments

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

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

    ~chris

  2. Johnny

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

Powered by WordPress & Theme by Anders Norén