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']

to

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.

About Aimred

Aimred is a specialist Ruby and Ruby on Rails development house and consultancy based in Cape Town, South Africa.

We provide Ruby and Ruby on Rails development, consulting and training services to businesses and organisations of all sizes. If you want to find out how we can help you, contact us at info@aimred.com.

Recent Posts

Yearly Archives