Run code before or after an existing Rake task


To run additional code before an existing Rake tasks you can add a dependency like this:

task :before_task do
  # runs before :existing_task

Rake::Tasks[:existing_task].enhance [:before_task]

The new dependency will be called after all existing dependencies.


To run additional code after an existing Rake tasks, pass a block to enhance:

Rake::Tasks[:existing_task].enhance do
  # runs after :existing task
Henning Koch 3 months ago
This website uses short-lived cookies to improve usability.
Accept or learn more