你如何在 Rake 任务之间进行通信? [英] How do you communicate between Rake tasks?

查看:27
本文介绍了你如何在 Rake 任务之间进行通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个需要编译一些文件的目标.该目标有另一个目标作为先决条件,即获取文件的目标.这么说吧:

Let's say I have a target who needs to compile some files. That target has another target as a prerequisite, one that obtains the files. Let's say this:

task :obtain do
  # obtain files from somewhere
end

task :compile => :obtain do
  # do compilation
end

假设 :obtain 目标并不总是将文件放在同一文件夹中.我如何将 :compile 传递给 :obtain 找到的路径?环境变量?

Let's say that the :obtain target doesn't always places the files in the same folder. How would I pass :compile the path that :obtain found? Environment variables?

推荐答案

在我看来,使用 ENV['something'] 更可取,因为如果你这样做(而不是 $global 或 @instance 变量)你可以将它们视为任务参数,并轻松使用命令行中的子任务.

Using ENV['something'] is in my opinion preferable, because if you do it this way (as opposed to $global or @instance variables) you can treat those as task arguments, and use the sub task from commandline easily.

另一方面,如果您将代码保存在单独的类/模块/方法中,您甚至不必处理这些类型的 hack + 您的代码将更具可测试性.

On the other hand if you keep your code in separate classes / modules / methods, you will not even have to deal with those sorts of hacks + your code will be more testable.

这篇关于你如何在 Rake 任务之间进行通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆