2016-06-13 31 views
0

這是我第一次使用rake,並且我發現文件依賴關係存在問題。Ruby Rake FILE方法不起作用

進行測試,在Rakefile.rb我把這個代碼:

task :ffile do 

    f1 = "config.yaml" 
    f2 = "Rakefile.rb" 

    if File.file? f1 then puts "## test file task on #{f1}" end 
    if File.file? f2 then puts "## test file task on #{f2}" end 

    file "#{f1}" => "#{f2}" do 
     puts "lol" 
    end 

    file "#{f2}" => "#{f1}" do 
     puts "lul" 
    end 

    file "#{f1}" do 
     puts "lil" 
    end 

    file "#{f2}" do 
     puts "lal" 
    end 

end 

我在Windows 10和運行時

rake ffile 

結果是

Starting rake operations... 
## test file task on config.yaml 
## test file task on Rakefile.rb 

文件方法在全部四種情況下什麼都不做。我也嘗試刪除所有file中的報價(即f1而不是"#{f1}"等等),但獲得相同的結果。 顯然,每次我在測試時保存Rakefile.rb,所以我確信應該觸發其中一個文件方法。

有語法錯誤嗎?它與Windows 10的故障排除?

由於

+0

什麼是'文件'應該做的?你能發佈代碼嗎? – floum

回答

0

謝謝larrylv,我明白了!

我有兩個錯誤:

  1. 圓形,如larrylv說
  2. ,我不調用文件的任務! (larrylv說)

所以我報告一個簡單的例子,工程

f1 = "config.yaml" 
f2 = "Rakefile.rb" 

task :ffile => ["#{f1}"] 

file "#{f1}" => ["#{f2}"] do 
    puts "lul" 
end 

這樣,命令rake ffile作品aspected。

謝謝!