我试图找到一种方法来修改/扩展一个RakeFile从另一个RakeFile实际上没有改变它。
当我运行我的rake任务时,我从SVN中检索一个包含rakefile的解决方案。 我要:
在这个rakefile中改变一个变量。 添加一个新任务到这个使用现有任务的rakefile。 执行新的任务。我希望在不实际修改光盘上的原始RakeFile的情况下执行此操作。
I'm trying to find a way to modify/extend a RakeFile from another RakeFile without actually changing it.
When I run my rake task I retrieve a solution from SVN which contains a rakefile. I want to:
Change a variable in this rakefile. Add a new task to this rakefile which makes use of existing tasks. Execute the new task.I want to do this preferably without actually modifying the original RakeFile on disc.
最满意答案
这是在执行任务之前运行任意代码的一种方法。
your_task = Rake::Task['task:name'] your_task.enhance { this_runs_before_the_task_executes }你可以类似地执行rake任务。
your_task.invoke完整的文档在这里 。
This is the code which I ended up with to solve the particular problem I was having.
Dir.chdir File.dirname(__FILE__) + '/their_app' load 'RakeFile' # Modify stuff from original RakeFile COMPILE_TARGET = "release" # Add my task task :my_task =>[:my_pre_task, :their_task]I don't know if this is the right way to do it and would appreciate comments/edits if anyone knows a better way.
Thanks to leethal for submitting a answer which helped me on the way and was very useful for another problem I was having.
我如何从另一个rake文件修改/扩展rake文件?(How can I modify/extend a rake file from another rake file?)我试图找到一种方法来修改/扩展一个RakeFile从另一个RakeFile实际上没有改变它。
当我运行我的rake任务时,我从SVN中检索一个包含rakefile的解决方案。 我要:
在这个rakefile中改变一个变量。 添加一个新任务到这个使用现有任务的rakefile。 执行新的任务。我希望在不实际修改光盘上的原始RakeFile的情况下执行此操作。
I'm trying to find a way to modify/extend a RakeFile from another RakeFile without actually changing it.
When I run my rake task I retrieve a solution from SVN which contains a rakefile. I want to:
Change a variable in this rakefile. Add a new task to this rakefile which makes use of existing tasks. Execute the new task.I want to do this preferably without actually modifying the original RakeFile on disc.
最满意答案
这是在执行任务之前运行任意代码的一种方法。
your_task = Rake::Task['task:name'] your_task.enhance { this_runs_before_the_task_executes }你可以类似地执行rake任务。
your_task.invoke完整的文档在这里 。
This is the code which I ended up with to solve the particular problem I was having.
Dir.chdir File.dirname(__FILE__) + '/their_app' load 'RakeFile' # Modify stuff from original RakeFile COMPILE_TARGET = "release" # Add my task task :my_task =>[:my_pre_task, :their_task]I don't know if this is the right way to do it and would appreciate comments/edits if anyone knows a better way.
Thanks to leethal for submitting a answer which helped me on the way and was very useful for another problem I was having.
发布评论