如何运行所有佣金任务?
task :a do
# stuff
end
task :b do
# stuff
end
task :c do
# stuff
end
task :all do
# Run all other tasks?
end
我知道我可以做到
task :all => [:a, :b, :c] do
end
但如果我添加新任务,我还需要将其添加到:all
依赖项。我会
喜欢避免手动操作,因为忘记似乎很容易。
答案 0 :(得分:1)
Here's one way:
namespace :hot_tasks do |hot_tasks_namespace|
task :task1 do
puts 1
end
task :task2 do
puts 2
end
task :all do
hot_tasks_namespace.tasks.each do |task|
Rake::Task[task].invoke
end
end
end
running it:
# bundle exec rake hot_tasks:all
1
2
More (not necessarily better) ideas at this question, especially if you're in a rails app.