Rake is a Make-like build utility for Ruby, using standard Ruby syntax to define tasks, prerequisites, and automated workflows.
Basic Task Syntax
In Rakefile:
desc "Run all project test suites"
task :test do
puts "Running tests..."
end
# Task with prerequisite dependencies
task deploy: [:test, :build] do
puts "Deploying application..."
end
# Default task invoked when running bare `rake`
task default: :test
Namespaces
Group related tasks logically:
namespace :db do
desc "Run database migrations"
task :migrate do
puts "Migrating database..."
end
desc "Rollback previous migration"
task :rollback do
puts "Rolling back..."
end
end
# Run in terminal: rake db:migrate
Task Arguments
desc "Send digest email to user by ID"
task :send_digest, [:user_id] do |_, args|
puts "Sending digest to user #{args[:user_id]}"
end
# Run in terminal: rake send_digest[42]
File Tasks
File tasks run only when target files do not exist or prerequisites are newer:
file "dist/bundle.js" => ["src/app.js", "src/utils.js"] do
sh "esbuild src/app.js --bundle --outfile=dist/bundle.js"
end