Arguments For Rake
Sometimes it pays to read the release notes. If I did that more often I would have known that as of Rake 0.8.0 it’s possible to pass arguments to rake tasks on the commandline. I first read about it in this article (via ruby.reddit.com) and applied it to the article I wrote previously on code generation. All it entailed was changing
1 task( :model_auto_rspec => 'sequel:merb_start' ) do 2 model_class = ENV['model']
1 task( :model_auto_rspec, :model , :needs => 'sequel:merb_start') do |task, args| 2 model_class = args.model
and calling it from the command line like so
1 rake generate:model_auto_rspec[User]
Farrel Lifson is a lead developer at Aimred.