Automating Project Tasks with Rake
Rake and the Rakefile are powerful tools for simplifying and automating complex, repetitive tasks, such as packaging Gems up, generating website HTML from HAML et al, performing complex repository backflips with a single command.
Samples
Here are some sample Rakefiles to get you familiar with the breadth that Rakefiles can cover.
- http://github.com/mtodd/halcyon/tree/site/Rakefile
- http://github.com/wycats/merb-core/tree/master/Rakefile
- http://github.com/macournoyer/thin/tree/master/Rakefile
- http://github.com/evanphx/rubinius/tree/master/Rakefile
Tasks
Tasks are defined with a description and a task body. For example:
desc "Remove generated content" task :clean do Rake::FileList["pkg/", "doc/", "**/*~", "**/*.bak"].each do |file| rm_r file rescue nil puts "* deleted #{File.basename(file)}" end end
Namespaces
Tasks can be grouped together under a namespace to provide organization and topical sub-tasks. For example:
namespace(:site) do desc "Remove compiled source files" task :clean do # implementation end desc "Generate dynamic files" task :generate => [:clean] do # implementation end
Prerequisites
When tasks are defined as a hash with an array (like the generate task in the site namespace above), the tasks named in the array are prerequisites and will be executed before the currently defined task.
page_revision: 3, last_edited: 1205969804|%e %b %Y, %H:%M %Z (%O ago)





