开发者

What can rakefiles be used for?

I understand the utility of the rake command, but what kinds of cus开发者_如何学编程tom 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".


Since you're asking for best practices, check out this book: Ruby Best Practices. Pages 234-237 talks about Rake files.

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.

Some applications for Rake that I've used personally:

  1. Test runs
  2. Gem packaging
  3. 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.


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?

You could use rake as a method to define command line options.

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜