[Rake-devel] Task for nested instance of Rake

Torsten at Robitzki.de Torsten at Robitzki.de
Thu Feb 24 03:01:21 EST 2011

Hello  Jesper

Am 23.02.2011 um 12:59 schrieb Jesper Tholstrup Pedersen (JUP):

> The second part is making the loaded rakefile run from the correct sub
> directory. 
> At the moment I have encapsulated this in a task.
> If you have any suggestions as to how the this could be packaged as a
> new task flavor, I'm all ears.

From what I've found: __FILE__ seems to be the currently executed Ruby script, so passing __FILE__ to the following function should yield in changing to the current ruby/rake script.

def set_current_directory source_file
	Dir.chdir File.dirname(source_file)
def task_from_current_directory source_file, *args, &block
	define_task(args) { set_current_directory source_file }
	define_task(args, block)
	// maybe it's worth thinking about setting the current directory back again here


task_from_current_directory __FILE__, :build do
	puts "task :build run."
	puts "Current directory: #{Dir.pwd}"

This is not tested, but I hope one can get the idea. I don't know how and when default arguments are added to a function call in ruby. Maybe it is possible to pass the __FILE__ as a default parameter.

best regards

More information about the Rake-devel mailing list