[Rake-devel] Setting a task's working directory on task definition

Matthew Curry mjcurry at gmail.com
Thu Jul 17 12:09:45 EDT 2008


Hello rake devs:

I wrote some code (as a redefinition of Rake classes) to support a new
function called dirspace.  Give dirspace a directory and a block as
arguments, and each rake task defined until the end of the block will
invoke and/or execute itself within that directory.

I wrote it because I was including several .rake files into one large
Rakefile at the top of my project, but still wanted the tasks defined
within each .rake to be 'anchored' at that file's directory.  Useless
for Rails people I suppose, but more helpful as a general Make
replacement as a way around respawning rake for each directory.

Obviously the code needs some cleaning up, but any comments are welcome.



Use similar to a namespace:

dirspace "/tmp" do
  task :clean_tmp do
    Dir.glob('*').each do |f|
      rm_f f
    end
  end
end


And now the clean_tmp task will always execute in the /tmp directory.

-Matt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dirspace.rb
Type: application/x-ruby
Size: 1535 bytes
Desc: not available
URL: <http://rubyforge.org/pipermail/rake-devel/attachments/20080717/550bfbdf/attachment.bin>


More information about the Rake-devel mailing list