【发布时间】:2015-08-19 17:48:01
【问题描述】:
我开始创建一组 Rake 任务(我的第一次,Ruby 经验有限),当我使用 rake test 或 rake db 从命令行运行第一个任务时,我得到两个输出,即使有只是相关目录中的一个文件。
rakefile.rb
require 'fileutils'
FILES = ["html", "css", "js", "svg", "otf", "eot", "ttf", "woff", "jpeg", "map", "ico", "map", "png", "db"]
desc 'test script'
task :test => [:db]
task :db do
copy_to 'data/', 'c:/xampp/htdocs/home/shared/data'
end
def copy_to(dest, src)
files = FileList.new()
files.include Dir.glob("#{src}/*.*")
FILES.each {|ext| files.include "#{src}/*.#{ext}"}
files.each do |src|
puts "copying: #{src} to #{dest}"
FileUtils.cp src, dest
end
end
输出
(in C:/xampp/htdocs/home/gateway)
copying: c:/xampp/htdocs/home/shared/data/foo.db to data/
copying: c:/xampp/htdocs/home/shared/data/foo.db to data/
当我执行rake -T 时,我得到以下信息(这是我所期望的):
(in C:/xampp/htdocs/home/gateway)
rake test # test script
当然foo.db 只会被复制一次,否则第二个副本会覆盖
第一个。
EDIT从命令行运行rake test --trace
** Invoke test (first_time)
** Invoke db (first_time)
** Execute db
copying: c:/xampp/htdocs/home/shared/data/foo.db to data/
copying: c:/xampp/htdocs/home/shared/data/foo.db to data/
** Execute test
它是否正在执行:db 和然后 :test?或者:db 是否像这里看起来那样运行两次?我错过了什么?我是不是做错了什么?
【问题讨论】: