2010-08-05 11 views

cevap

16

Ben cevabı öğrendim. Eğer yazdığı gibi http://rake.rubyforge.org/

+0

Bildiğim kadarıyla ben gördüğümüz gibi, bir kapsamda şeyler bulmak için bir yardımcı yoktur, ama bu yeterince kolay olması gerektiğini düşünüyorum: Rake.application.tasks.reject {| görevi | task.scope! = [: your,: scope]} – phoet

+1

Benim durumumda (Rails), aynı zamanda "AppName :: Application.load_tasks" komutunu çalıştırmak için de gerekliydi. "Rake.application.tasks" – joshfindit

1

de diğer ayrıntıları Sen Rake.application.tasks ile tüm görevleri olsun, bu

desc 'Test' 
task :test do 
    # You can change db: by any other namespaces 
    result = %x[rake -T | sed -n '/db:/{/grep/!p;}' | awk '{print$2}'] 
    result.each_line do |t| 
     puts t # Where t is your task name 
    end 
end 
+0

bu gerçekten sadece Bir kapsam içindeki görevleri bulmak için olası bir çözüm ?! – phoet

+0

Aklıma gelen ilk şey bu. – garno

+0

mükemmel bir örnek, teşekkürler –

11

gibi grep komutunu kullanabilirsiniz.

Ama isim alanı içinde, sen ad (görev mytest: tasklist) sadece görevleri seçebilirsiniz

Ve eğer bir ad (görev tasklist_mytest) görevleri kısıtlayabilir.

require 'rake' 

namespace :mytest do |ns| 

    task :foo do |t| 
    puts "You called task #{t}" 
    end 

    task :bar do |t| 
    puts "You called task #{t}" 
    end 

    desc 'Get tasks inside actual namespace' 
    task :tasklist do 
    puts 'All tasks of "mytest":' 
    puts ns.tasks #ns is defined as block-argument 
    end 

end 

desc 'Get all tasks' 
task :tasklist do 
    puts 'All tasks:' 
    puts Rake.application.tasks 
end 

desc 'Get tasks outside the namespace' 
task :tasklist_mytest do 
    puts 'All tasks of "mytest":' 
    Rake.application.in_namespace(:mytest){|x| 
    puts x.tasks 
    } 
end 

if $0 == __FILE__ 
    Rake.application['tasklist'].invoke() #all tasks 
    Rake.application['mytest:tasklist'].invoke() #tasks of mytest 
    Rake.application['tasklist_mytest'].invoke() #tasks of mytest 
end 
İlgili konular