It\'s not possible to invoke
the same rake task from within a loop more than once. But, I want to be able to call rake first
and loop through an array
FWIW this might help someone so I'll post it.
I wanted to be able to run one command from the CLI to run one Rake task multiple times (each time with new arguments, but that's not important).
Example:
rake my_task[x] my_task[y] my_task[z]
However, since Rake sees all my_task
as the same task regardless of the args, it will only invoke the first time my_task[x]
and will not invoke my_task[y]
and my_task[z]
.
Using the Rake::Task#reenable
method as mentioned in the other answers, I wrote a reenable
Rake task which you can position to run after a task to allow it to run again.
Result:
rake my_task[x] reenable[my_task] my_task[y] reenable[my_task] my_task[z]
I wouldn't say this is ideal but it works for my case.
reenable
Rake task source:task :reenable, [:taskname] do |_task, args|
Rake::Task[args[:taskname]].reenable
Rake::Task[:reenable].reenable
end