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...
參考文獻