2012-10-12 111 views
4

爲什麼這rake任務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 

只有實際運行第一組遷徙,無論是寶石/寶石順序/隨機調用重新啓用我用?

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. 

回答

5

invoke方法只運行「按需」,這基本上意味着,一旦它運行一次,它不會再次運行,除非重新啓用。

您可以在每個.invoke之後調用.reenable來重置它,或使用.execute命令來運行該任務。

.execute的警告是它不會運行任務的依賴關係,如果你有它們。

Why is Rake not able to invoke multiple tasks consecutively?

How to run Rake tasks from within Rake tasks?

+0

確定,但是,關於問題,需要重新啓用 「railties:安裝:遷移」 每個瑞克::任務[ 「#{}創業板:安裝:遷移」。執行或調用,一切都很好。 –