【问题标题】:Rake : List / Remove custom rake task in specific environment (development / production )Rake:列出/删除特定环境中的自定义 rake 任务(开发/生产)
【发布时间】:2015-10-29 13:52:54
【问题描述】:
有什么方法可以让我的自定义 rake 任务仅在 development 环境中列出,而不在 production 和 QA 中列出?
我的意思是,当我在 qa 或 production 环境中调用 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