1 min readNov 8, 2019
If anyone is facing an issue where the after hook get executed before the main task
use the `at_exit` block provided by ruby. This ensures the after_hook runs after the main task has executed.
task :before_hook do
puts "Before hook"
endtask :after_hook do
at_exit do
puts "After hook"
end
endtasks = Rake.application.tasks
tasks.each do |task|
next if [Rake::Task['before_hook'],
Rake::Task['after_hook']].include?(task)task.enhance([:before_hook, :after_hook])
end