The original Dr Nic’s Magic Models were named as such because I entertained the idea of showing them off as a live magic show. So, given 3 minutes in front of some of the Ruby community’s hottest hackers, I got my chance! Not the Original Magic Models, but the never-before-released Magic Model Generator.
How to install and use the
magic_model_generator follows the video from RejectConf:
The Magic Show
How to use it
Create a rails application, and point it to your database.
$ rails magic_show -d [mysql|sqlite|postgresql|oracle|etc|etc] $ cd magic_show $ cp database.yml.sample database.yml and point it to your database.yml to your legacy database
I use the database created for the ActiveRecord test cases –
activerecord_unittest. If you’ve never downloaded the activerecord gem, run
rake build_[mysql|sqlite|postgresql|oracle|etc|etc]_databases, and then
rake test_[mysql|sqlite|postgresql|oracle|etc|etc], then you’ve probably got more free time than I do as a result and I appreciate that. And so does my wife.
Now install the
$ sudo gem install magic_model_generator
Nonetheless, you’re done. That’s all the preparation I did for the video.
Next I recreated the
schema.rb file and the schema_info database table via
Next I ran the generator:
$ ./script/generate magic_model
And we’re done.
The MMG is awesome.
The one major drawback of the MMG is the same drawback of all rails generators: if you want to regenerate your models (say you update your schema via migrations) then you cannot regenerate your model associations and validations without completely recreating the file, thus destroying anything else you wrote. Which is useless.
The world of version control (subversion, cvs, etc etc) already solved this problem: merging. So I’m investigating adding merging to the rails_generator. That should be neat.
New Gem Generate to get merging too?
Currently the newgem command doesn’t use the rails_generator for creating files. So adding merging to rails_generator won’t help newgem. That is, unless I rewrite newgem. So, I’ll look into that too.
- NewGem Generator – now with script/generate The New Gem Generator (0.13.0)’s newgem command now behaves like...
- Magic Wiggly Lines => GuessMethod, by Chris Shea If you ever make time to code just for pleasure,...
- New Gem Generator gets RSpec [video] One day you will be able to write a...
- “Reads -> slaves, writes -> master” plugin Another solution to multiple connections in Rails has been put...
- Magic Multi-Connections: A “facility in Rails to talk to more than one database at a time” At this point in time thereâ€™s no facility in Rails...