guillermo / rake-hooks

Rake hooks let you add callbacks to rake tasks.
MIT License
70 stars 21 forks source link

How to use this with namespaces? #12

Open benissimo opened 12 years ago

benissimo commented 12 years ago

I tried:

namespace :db do before :migrate do puts "before db:migrate" end end

but that triggers errors about calling full_comment on nil.

I also tried

before "db:migrate"

and

before "db:migrate".to_sym

No luck with those either.

I found an alternative approach just using the built-in capacities of rake documented here: http://whynotwiki.com/Rake#Can_I_.22append.22_to_.2F_add_a_postrequisite_to_a_task.3F

But I like the rake-hooks syntax and would gladly use it if I could get it to work with namespaced tasks.

guillermo commented 12 years ago

Can you please attach a patch for solving this?

chrislewis60 commented 11 years ago

It does work with namespaces ... like this:

namespace :greetings do 
    task :hola     do puts "Hola!" end ;
    task :bonjour do puts "Bonjour!" end ;
    task :gday    do puts "G'day!" end ;  
end 

before "greetings:hola", "greetings:bonjour", "greetings:gday" do
  puts "Hello!"
end

rake greetings:hola # => "Hello! Hola!" 

I've also written a couple of tests to demonstrate that it works with namespaces. Let me know if you want them.

p.s. the "before" call has to come after the namespace and outside of it.