我有一堆 rake 构建任务。
它们每个都有独特的输入/输出属性,但我每次在任务上设置的大多数属性都是相同的。目前我正在通过像这样的简单重复来做到这一点:
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
在我通常的编程领域,我希望能够将重复任务属性的数量分解为可重用的函数。
有没有类似的 rake ?我可以通过某种方式拥有一个在任何任务上设置共享属性的函数吗?相当于:
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
谢谢。
======
回复SR:
谢谢斯蒂芬,
我显然错过了一些东西 - 我有:
desc 'Compile run the test harness'
unit :test do |t|
populate_test_task(t)
end
def populate_test_task(t)
t.source_path << "support"
t.prepended_args = '+configname=air -define+=CONFIG::LocalDebug,true'
end
我尝试在任务之后立即定义函数(此文件中没有命名空间:),并在最后一个任务之后的文件末尾定义函数,并且我得到“main的未定义方法‘populate_test_task’: Object” - 在我看来,它没有找到该函数。
我错过了什么?
最佳答案
您可以调用 rake 文件下方定义的常规方法,例如
namespace :build do desc 'builds ABC module' task :abc do build_mod('abc') end desc 'builds DEF module' taks :def do build_mod('def') end end def build_mod(module_name) # stuff to build the module end
然后使用 rake build:abc 和 rake build:def 调用它
SR
关于ruby - 避免在 Rake 任务中重复设置任务属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2945111/