One day you will be able to write a human description of a RubyGem and it will make it for you. Ok, that’s crap. But the New Gem Generator is doing more and more cooler things lately; so let’s take a peek…
For a growing number of people, RSpec is the way to go, over the Test::Unit test suite. Now, thanks to a contribution from Robby Russell and Graeme Nelson during Railsconf.
New gems now have a website folder with an index.txt file (redcloth format). Put your glorious promotional materials and tutorials here (plus add additional .txt files as well) and the rake website task will convert them to html files and upload them to your rubyforge website.
The standard template looks like this (you’re encouraged to change some colours or fonts!)
Ready to release a new X.Y.Z version of your gem? It takes 3 minutes.
Set the version number in lib//version.rb.
Check your Manifest.txt that it includes all new files (via rake check_manifest)
Update History.txt with changes. The default supported format is 2 paragraphs – a header and group of bullet points; these look nice when converted to rdoc format.
Commit the new version to repository.
$ rake deploy VERSION=X.Y.Z
This will release your RubyGem to rubyforge so people can install it; plus upload your website and your rdocs.
You’ll then be prompted to commit a copy of the trunk as a tag REL-X.Y.Z. This could be very useful one day!
Video of NewGem at RejectConf
You can read the pdf slides and/or watch the presentation from RejectConf:
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 magic_model_generator gem:
$ 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 rake db:migrate.
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.
I’ve been a fan of Ryan Davis‘ (zenspider) and Eric Hodel‘ ZenTest library (including its autotest CI tool for rails and gems), and their Hoe gem, the Rubyforge gem, etc ever since I figured out what they did. (Side note: how to setup rubyforge gem)
Ryan shows this off at RejectConf; its 16 minutes but definitely worth your time to investigate, as I think this will be awesome for ensuring basic edge cases are thoroughly tested. Can a guest create something? Can a member delete something?
It is hard to see the code on the screen, but look at the blog posts linked above to get the gist of what is being shown.
People were really interested this as you can tell by the huge number of questions, despite this being the last of many many presentations.
This stuff looks primed for a sweet generator to create the test file.