Run code before or after an existing Rake task

Updated . Posted . Visible to the public.

Before

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

task :before_task do
  # runs before :existing_task
end

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

The new dependency will be called after all existing dependencies.

After

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

Rake::Task[:existing_task].enhance do
  # runs after :existing task
end
Henning Koch
Last edit
Henning Koch
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2021-04-22 12:22)