rake-hooks icon indicating copy to clipboard operation
rake-hooks copied to clipboard

How to use this with namespaces?

Open benissimo opened this issue 14 years ago • 2 comments

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.

benissimo avatar Jun 08 '12 11:06 benissimo

Can you please attach a patch for solving this?

guillermo avatar Aug 12 '12 13:08 guillermo

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.

chrislewis60 avatar Feb 05 '13 10:02 chrislewis60