Rake is set up much like Make in that a Rakefile consists of targets and dependencies. This is different from a regular ruby script in that Rake starts at the target you ask for and recursively executes its dependencies before executing the target itself.
So, install might look like this:
task :install => :stage do
# stuff to do
end
Here, your target is the install
task, and it depends on some other task called stage
.
To execute install
, Rake must first execute the dependencies of stage
(if it has any), then stage
, then finally it executes install
. So no, you don't execute the whole file, just enough of it to safely execute the target you asked for.
Rake also supports file targets:
file 'foo.html' => 'bar.xml' do |t|
# Build foo.html from bar.xml, however that is done
end
If you know Make, this looks familiar. Rake first checks whether bar.xml
depends on anything, and if so, it executes that. Then, if bar.xml
is newer than foo.html
, then Rake executes this file task. If foo.html
is newer, then Rake assumes that it has aleady been built and skips it.
For more, the Rake User Guide is a good place to start if you want to learn what Rake does.