Ruby rake
Rake 是 Ruby 中类似 Make 的任务运行器。首先在 Rakefile
中以 ruby 语法定义任务列表,然后使用 rake 命令调用任务。
Examples of usage
- Most basic task
# inside Rakefile
task :hello do
puts 'hello, world'
end
# open console of the current directory
# $ rake hello
# hello, world
- Namespacing tasks
# inside Rakefile
namespace :db do
task :backup do
puts 'backing up database...'
end
end
# open console of the current directory
# $ rake db:backup
# backing up database...
- Dependent tasks
# inside Rakefile
task :clean do
puts 'cleaning...'
end
task :build => :clean do
puts 'building...'
end
task :test => [:build, :clean] do
puts 'testing...'
end
# open console of the current directory
# $ rake build
# cleaning...
# building...
# $ rake test
# cleaning...
# building...
# testing...
- Grouping tasks
# inside Rakefile
task :clean do
puts 'cleaning...'
end
task :build => :clean do
puts 'building...'
end
task package: [:clean, :build]
task default: :clean
# open console of the current directory
# $ rake package
# cleaning...
# building...
# without specifying task will execute the default
# $ rake
# cleaning...
参考资料