Thursday, July 16, 2009

Rake and task arguments

I'm putting this together because I really like Rake for the most part, but there is an irritating tendency for the docs to fall out of currency. And they like the #nodoc tag. A lot.

So, in more recent versions of Rake (0.8.6 or thereabouts), you can use arguments to tasks, like this:


task :my_task, [:whick, :whack] => [:depend_on] do |task, args|
args.with_defaults(:whack => 42)
end


(Actually, there's about a dozen (well, four) different formats for task definition, but there's 20 reasonable formats that won't work, and I've found that the :task, [:args] => [:deps] format is the best one to remember.)

Now, if a dependency also has arguments, and they're a subset of the primary tasks arguments, then they'll be assigned, regardless of their relative order.

task :depend_on, [:whack] do; end

:depend_on will get :whack assigned from the arguments assigned by :my_task.

No comments:

Post a Comment