First some notes about IDE’s.

The Knight versus the Ninja

kletch…. kletch…. a loud noise of kletching metal combined with slight floor vibrations left the hall. It was The Knight. His scarred and angry face showed that he was a well experienced warrior, ready for another day of combat for the greater collective cause.

shhh…. shhhh…. what was that? It was probably just the wind. The next day we found the victim dead, with a shuriken-metal-star in his head. The Ninja has made another kill, fighting for the feudal ruler.

If you are the Knight, click here. If you are the agile Ninja, read on.

Using IRB and the Rails Console

A little while ago I read this great article about the Secrets of the Rails Console Ninja’s

My current Rails job in Tokyo required me to use the RadRails IDE on Windows to work on a legacy part the first weeks. The constant switch between script/console, RadRails and my browser inspired me to merge the first two. (Also, sometimes I got rails errors because of :wq symbols in wrong places ;)

I’ve named it Shuriken (the ninja death star) the tool for Rails Console Ninja’s.

You can download it as a .irbrc file which you can just place in your homedir.

download .irbrc

Shuriken

Downloading shuriken, place .irbrc in your homedir.

dodo@membrane$ wget http://www.darkwired.org/~dodo/.irbrc
Create a project or use an existing one and startup the console.
dodo@membrane$ rails webapp > /dev/null; cd webapp
dodo@membrane$ ./script/console
Loading development environment.
Loading IRB shuriken technique
rails development>>
Creating a controller from IRB, after creation we can use it right away.
rails development>> script/generate controller skinny info
      exists  app/controllers/
      exists  app/helpers/
      create  app/views/skinny
      create  test/functional/
      create  app/controllers/skinny_controller.rb
      create  test/functional/skinny_controller_test.rb
      create  app/helpers/skinny_helper.rb
      create  app/views/skinny/info.rhtml
# => true
rails development>> SkinnyController.instance_methods.index("info")
# => 175
Display an overview of controllers:
rails development>> map controllers
  SkinnyController
# => "app/controllers" 
rails development>> map c
  SkinnyController
# => "app/controllers" 
Use vim – the editor from heaven – to open the controller
rails development>> vim skinny_controller
# => "app/controllers/skinny_controller.rb" 
Displaying views (models is also possible)
rails development>> map views # or 'map v'
  Layouts
  Skinny/Info
# => "app/views" 
Using subversion ‘svn ste’ is an alias for: “svn status | grep -v ’?
rails development>> svn ste '" 
A      .
A      README
M      app/controllers/skinny_controller.rb
# => "app/views" 
Executing commands.
rails development>> !uname
Linux
# => true
Unit testing (or selenium testing).
rails development>> map tests # or 'map t'
  Functional/SkinnyControllerTest
# => "test" 
rails development>> rake test
...
Running in production mode:
dodo@membrane$ ./script/console production
Loading production environment.
Loading IRB shuriken technique
rails production>>

TODO

  • get feedback from users
  • add these commands to IRB auto-completer (readline)
  • add more useful stuff, then cleanup code