我在Ruby 1.9.3项目中有以下Rakefile:
require 'rake/testtask'
require 'json'
Rake::TestTask.new do |t|
t.pattern = "spec/**/*_spec.rb"
t.verbose = true
end
task :default => :test
namespace :omglol do
namespace :file_a do
task :foo do
# do some stuff
end
end
namespace :file_b do
task :bar do
# do some stuff
end
end
end如您所见,此文件的第一部分允许运行测试,只需使用rake命令即可。第二部分包含了一些任务。
实际上,我在omglol:file_a和omglol:file_b名称空间中有很多任务。这就是为什么我想把它们都移动到一个文件中,例如tasks/omglol/file_a.rake和tasks/omglol/file_b.rake。
有没有最好的方法呢?谢谢。
发布于 2012-08-08 06:49:21
是。只需将逻辑移动到适当的文件中,然后require它们。
示例Rakefile:
require 'rake/testtask'
require 'json'
require 'lib/tasks/omglol/file_a.rake' # <= contains your subtasks
Rake::TestTask.new do |t|
t.pattern = "spec/**/*_spec.rb"
t.verbose = true
end
task :default => :test然后在lib/tasks/omglol/file_a.rake中,只需像平常一样定义您的任务:
namespace :omglol do
namespace :file_a do
task :foo do
# do some stuff
end
end
endfile_b.rake的模式也是一样的。
https://stackoverflow.com/questions/10097629
复制相似问题