为什么这个rake任务
gems = %w(gem1 gem2 gem3)
namespace :gems do
namespace :install do
desc "Runs install:migrations for all gems"
task :migrations do
gems.each do |gem_name|
print "\nInstalling migrations for the #{gem_name} gem...\n"
Rake::Task["#{gem_name}:install:migrations"].invoke
end
print "\n\nGem migrations installed."
end
end
end
只实际运行第一组迁移,不管我使用的 gems/gem 排序/随机调用重新启用?
Installing migrations for the gem1 gem...
Copied migration whatever from gem1
Copied migration whatever from gem1
Copied migration whatever from gem1
Copied migration whatever from gem1
Installing migrations for the gem2 gem...
(nothing)
Installing migrations for the gem3 gem...
(nothing)
Gem migrations installed.
最佳答案
invoke
方法仅“根据需要”运行,这基本上意味着一旦运行一次,除非重新启用,否则不会再次运行。
您可以在每次 .invoke
之后调用 .reenable
来重置它,或者使用 .execute
命令来运行任务。
.execute
的警告是,如果您有它们,它不会运行任务的依赖项。
Why is Rake not able to invoke multiple tasks consecutively?
关于ruby-on-rails - 用于安装仅执行一次的 gem 迁移的 Rake 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12865776/