2

Is there any way to make my custom rake tasks only listed in development environment but not in production and QA?

I mean, when I invoke bundle exec rake -T in qa or production env, it should not list my custom rake tasks but it should in development.

Shiva
  • 11,485
  • 2
  • 67
  • 84

1 Answers1

3

You can add this to the application Rakefile (after 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
markets
  • 6,709
  • 1
  • 38
  • 48