I understand the utility of the rake
command, but what kinds of custom actions are typically defined in the Rakefile? I'm new and trying to figure out when it's appropriate to use this feature. I've found out plenty about how to use it, but not much about "best practices".
我理解rake命令的用途,但是Rakefile中通常定义了什么类型的自定义操作?我是新来的,想弄清楚什么时候使用这个功能是合适的。我已经找到了很多关于如何使用它的方法,但是没有太多关于“最佳实践”的内容。
3 个解决方案
#1
4
Since you're asking for best practices, check out this book: Ruby Best Practices. Pages 234-237 talks about Rake files.
既然您正在寻求最佳实践,请参阅这本书:Ruby最佳实践。第234-237页讨论了Rake文件。
To paraphrase, it enhances the discoverability of tasks in your project so that users unfamiliar with it can start doing useful things quickly.
换句话说,它增强了项目中任务的可发现性,因此不熟悉它的用户可以快速地开始做有用的事情。
A good practice is to add desc() strings for your Rake tasks so that rake -- tasks
provides meaningful output.
一个好的实践是为您的Rake任务添加desc()字符串,以便Rake—tasks提供有意义的输出。
Some applications for Rake that I've used personally:
我个人用过的Rake一些应用:
- Test runs
- 测试运行
- Gem packaging
- 珠宝包装
- Documentation generation
- 文档生成
Other examples include publishing code/documentation updates to Rubyforge automatically, etc. Basically, virtually anything that can be done at a command line can be done in Rake and your imagination's the limit.
其他示例包括自动向Rubyforge发布代码/文档更新等。基本上,几乎任何可以在命令行中完成的操作都可以在Rake中完成,而您的想象力是the limit。
#2
3
Answering to your followup-question in Chads answer:
回答以下问题:
Just a followup - what is the advantage to using rake over calling a ruby file with the interpreter directly?
仅仅是一个后续——使用rake直接与解释器调用ruby文件有什么好处呢?
You could use rake as a method to define command line options.
您可以使用rake作为一个方法来定义命令行选项。
I often use it like this:
我经常这样使用它:
require 'rake'
#
# Your task definitions
#
task :default => :mytask
if $0 == __FILE__
app = Rake.application
app[:default].invoke
end
If I execute the script, my default task is running. But I may also start it via rake on command line.
如果执行脚本,则默认任务正在运行。但是我也可以通过命令行来启动它。
#3
1
Rake could be used for any kind of batch command, most people use things like setting up, installing, running, cleaning, or other application related actions.
Rake可以用于任何类型的批处理命令,大多数人使用诸如设置、安装、运行、清理或其他与应用程序相关的操作。
#1
4
Since you're asking for best practices, check out this book: Ruby Best Practices. Pages 234-237 talks about Rake files.
既然您正在寻求最佳实践,请参阅这本书:Ruby最佳实践。第234-237页讨论了Rake文件。
To paraphrase, it enhances the discoverability of tasks in your project so that users unfamiliar with it can start doing useful things quickly.
换句话说,它增强了项目中任务的可发现性,因此不熟悉它的用户可以快速地开始做有用的事情。
A good practice is to add desc() strings for your Rake tasks so that rake -- tasks
provides meaningful output.
一个好的实践是为您的Rake任务添加desc()字符串,以便Rake—tasks提供有意义的输出。
Some applications for Rake that I've used personally:
我个人用过的Rake一些应用:
- Test runs
- 测试运行
- Gem packaging
- 珠宝包装
- Documentation generation
- 文档生成
Other examples include publishing code/documentation updates to Rubyforge automatically, etc. Basically, virtually anything that can be done at a command line can be done in Rake and your imagination's the limit.
其他示例包括自动向Rubyforge发布代码/文档更新等。基本上,几乎任何可以在命令行中完成的操作都可以在Rake中完成,而您的想象力是the limit。
#2
3
Answering to your followup-question in Chads answer:
回答以下问题:
Just a followup - what is the advantage to using rake over calling a ruby file with the interpreter directly?
仅仅是一个后续——使用rake直接与解释器调用ruby文件有什么好处呢?
You could use rake as a method to define command line options.
您可以使用rake作为一个方法来定义命令行选项。
I often use it like this:
我经常这样使用它:
require 'rake'
#
# Your task definitions
#
task :default => :mytask
if $0 == __FILE__
app = Rake.application
app[:default].invoke
end
If I execute the script, my default task is running. But I may also start it via rake on command line.
如果执行脚本,则默认任务正在运行。但是我也可以通过命令行来启动它。
#3
1
Rake could be used for any kind of batch command, most people use things like setting up, installing, running, cleaning, or other application related actions.
Rake可以用于任何类型的批处理命令,大多数人使用诸如设置、安装、运行、清理或其他与应用程序相关的操作。