Passing Parameters to Rake Tasks
I recently discovered how to correctly pass parameters to Rake tasks from the command-line instead of the old, busted way of passing in environment variables. The post is up on the Viget Extend blog, but here's the short of it.
If you have a task that you want to parameterize:
task :echo do puts "Hello" end
You can specify the parameters that it accepts and receive them as a hash inside of the task:
task :echo, :message do |t, args| message = args[:message] || 'Hello' puts message end
It also honors task dependencies (using a different syntax):
task :echo, :message, :needs => :environment do |t, args| ... end
Check out the post for the full details.
