Avoiding duplication in setting properties on the task in Rake tasks

Posted by Stray on Stack Overflow See other posts from Stack Overflow or by Stray
Published on 2010-05-31T17:38:31Z Indexed on 2010/05/31 17:43 UTC
Read the original article Hit count: 215

Filed under:
|

I have a bunch of rake building tasks.

They each have unique input / output properties, but the majority of the properties I set on the tasks are the same each time. Currently I'm doing that via simple repetition like this:

task :buildThisModule => "bin/modules/thisModule.swf"

mxmlc "bin/modules/thisModule.swf" do |t|
    t.input = "src/project/modules/ThisModule.as"
    t.prop1 = value1
    t.prop2 = value2 ... (And many more property=value sets that are the same in each task)
end


task :buildThatModule => "bin/modules/thatModule.swf"

mxmlc "bin/modules/thatModule.swf" do |t|
    t.input = "src/project/modules/ThatModule.as"
    t.prop1 = value1
    t.prop2 = value2 ... (And many more property=value sets that are the same in each task)
end

In my usual programming headspace I'd expect to be able to break out the population of the recurring task properties to a re-usable function.

Is there a rake analogy for this? Some way I can have a single function where the shared properties are set on any task? Something equivalent to:

task :buildThisModule => "bin/modules/thisModule.swf"

mxmlc "bin/modules/thisModule.swf" do |t|
    addCommonTaskParameters(t)
    t.input = "src/project/modules/ThisModule.as"
end


task :buildThatModule => "bin/modules/thatModule.swf"

mxmlc "bin/modules/thatModule.swf" do |t|
    addCommonTaskParameters(t)
    t.input = "src/project/modules/ThatModule.as"
end

Thanks.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about rake