Rake:列出/删除特定环境中的自定义rake任务(开发/生产)

时间:2015-08-06 12:08:45

标签: ruby-on-rails ruby rake bundler

有没有办法让我的自定义佣金任务仅列在development环境中,而不是productionQA中?

我的意思是,当我在bundle exec rake -Tqa env中调用production时,它不应该列出我的自定义rake tasks,但它应该在development中。< / p>

1 个答案:

答案 0 :(得分:3)

您可以将其添加到应用RakefileMyRailsApp::Application.load_tasks行之后):

if Rails.env == "production"
  # add here the tasks you want to disable
  tasks_to_disable = [
    "db:drop",
    "db:reset"
  ]
  tasks = Rake.application.instance_variable_get("@tasks")
  tasks.delete_if { |task_name, _| tasks_to_disable.include?(task_name) }
end