Back to Web-Dev

Rake is a utility for build automation, based on unix utility make. It is a part of the rails command line. Rakefile can be used to set up a suite of automation commands (as in Rails).

Rakefile and .rake files to build lists of tasks.

Writing Rake Tasks

In rails, rails g task generates rake files.

namespace :db do # not required
  desc "some description for task"
  task task_name: [:prerequisite_tasks, :other_tasks_run_before] do
    # Any ruby code

Creates a rake task that can be called with $ bin/rake db:task_name

task :task_name, [:arg_1, :arg_2] => [:pre_1, :pre_2] do |t, args|
  # code

Creates a rake task called by $ bin/rake task_name[1, 'x'] which passes 1 and x as parameters. (zsh you need to escape square brackets)

In Rails


Rakefile describes a set of rake tasks that are available.

task :name
task :name => [:prereq1]
task :name do |t|
    # actions

Read More

Rake Task Design