运行所有rake任务?

时间:2017-04-09 22:36:22

标签: ruby rake rake-task rakefile

如何运行所有佣金任务?

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依赖项。我会 喜欢避免手动操作,因为忘记似乎很容易。

1 个答案:

答案 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.