Dec 09 Invoking Rake tasks more than once inside another task
tags:
You have a Rake task that needs to invoke another task several times, but it turns out you cannot do it right away. It is so because Rake is a dependency beast
To be able to invoke the required task more than once your dependant task needs to reenable the required task (the dependency) in order to run it over and over again.
Here it is (as a bonus we are passing down an anonymous parameter to the invoked task):
desc 'task that runs another task several times and passes anonymous param also :-)'
task :dependant_task do
%w(one two three).each do |anonimous_param|
ARGV[ 1 ] = anonimous_param
Rake::Task["repeated_task"].invoke
Rake::Task["repeated_task"].reenable
end
end