Ruby rake

Rake is a Make-like task runner in Ruby. First define a list of tasks in ruby syntax in a Rakefile and then invoke the task with rake command.

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...

References

ruby