tags:

views:

408

answers:

2

I'm trying to find a way to modify/extend a RakeFile from another RakeFile without actually changing it.

When I run my rake task I retrieve a solution from SVN which contains a rakefile. I want to:

  1. Change a variable in this rakefile.
  2. Add a new task to this rakefile which makes use of existing tasks.
  3. Execute the new task.

I want to do this preferably without actually modifying the original RakeFile on disc.

+4  A: 

Here's a way to run arbitrary code prior to executing the task.

your_task = Rake::Task['task:name']
your_task.enhance { this_runs_before_the_task_executes }

You can execute rake tasks similarly.

your_task.invoke

Full docs here.

August Lilleaas
A: 

This is the code which I ended up with to solve the particular problem I was having.

Dir.chdir File.dirname(__FILE__) + '/their_app'
load 'RakeFile'

# Modify stuff from original RakeFile
COMPILE_TARGET = "release"

# Add my task
task :my_task =>[:my_pre_task, :their_task]

I don't know if this is the right way to do it and would appreciate comments/edits if anyone knows a better way.

Thanks to leethal for submitting a answer which helped me on the way and was very useful for another problem I was having.

maz