【问题标题】:Rake : List / Remove custom rake task in specific environment (development / production )Rake:列出/删除特定环境中的自定义 rake 任务(开发/生产)
【发布时间】:2015-10-29 13:52:54
【问题描述】:

有什么方法可以让我的自定义 rake 任务仅在 development 环境中列出,而不在 productionQA 中列出?

我的意思是,当我在 qaproduction 环境中调用 bundle exec rake -T 时,它不应该列出我的自定义 rake tasks,但它应该在 development 中。

【问题讨论】:

    标签: ruby-on-rails ruby rake bundler


    【解决方案1】:

    您可以将此添加到应用程序Rakefile(在MyRailsApp::Application.load_tasksline 之后):

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-13
      • 2016-11-13
      • 2014-10-22
      • 2014-02-28
      • 2014-04-19
      • 2015-03-10
      • 1970-01-01
      相关资源
      最近更新 更多