views:

324

answers:

3

I'd like to install a plugin but I'm afraid it's going to install a lot of unnecessary stuff. I'd like to look at whatever file rake takes it installation instructions from and remove anything unnecessary.

I believe this is the Rakefile. But I'm not sure what happens when rake looks at the rakefile - does it execute the entire rakefile or only parts of the rakefile that are designated as being relevant to this "install" procedure?

A: 

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.

tgamblin
I was going to write the same task dependency example but then I thought ... "compiling" in ruby? :D
Pablo Fernandez
Good point. Heh.
tgamblin
+1  A: 

a rake file is a collection of tasks, when you call rake with an argument (in this case install) that's the task that get's executed. (It's similar to ant if you come from Java)

So, no, rake does not execute the whole rakefile when you call "rake + task" but only the task chosen. Note that tasks can have dependencies (eg the "test" task may depend on other previous tasks, like creating some folders and stuff for the tests to run).

Lastly, the rake user guide as pointed by other users is useful, but I recommend a more enjoyable read here -> Ruby on Rails Rake tutorial.

Pablo Fernandez
Also, if you do "rake install --dry-run" you'll see what tasks rake will execute without any of the processing actually taking place.
Shadwell
A: 

Why would a plugin install something "unnecessary"?

Assuming your fears are justified, though, could you not install the plugin, do your investigation and then, if not satisfied, revert to the pre-installed version using your source control system? If you're not using source control, this might be the perfect excuse to start...

Mike Woodhouse