Wednesday, November 7, 2007

Translate Rails 2.0 Schemas Into 1.2.3

Here's some code which allows you to translate Rails 2 preview release schemas into Rails 1.2.3 schemas.

Obviously 2.0 is more exciting than 1.2.3 (or 1.2.5, which is really what you should be on). However, if you've got an app you want to build fast, you want to be on the stable version of the platform.

The code works for my situation, but if you use it, you'll need to accomodate the possibility of single quotes rather than double quotes, and maybe some similar things. Caveat emptor, don't try this at home, etc.

As a side note, IRB and Ruby are so much better for developing regular expressions than the Perl I'm used to (when it comes to regexes) that it almost boggles the mind. Go in IRB and do this:

/my regex/.match("my string")

If it doesn't work, arrow up, edit the command, and start again. Lather, rinse, repeat. If you're using Ben Bleything's history code, and my variation which sends the history buffer to vi, you're really set, because every time you come up with a complex regex that matches a complex string, you can call the history_to_vi method and save off the one-liner as a test case.

(I'll release my variations on Ben's code soon.)