Custom Rake Tasks How to add custom Rake tasks
Custom Rake Tasks
If you want to add custom Rake tasks to your Hanami project, you have two ways: Rakefile
and .rake
files.
Rakefile
Rakefile
is the main Rake file of the project.
Add here your Rake tasks to perform general related activities.
The special :environment
task can be used as a task dependency to load the entire code of the project.
# Rakefile
namespace :db do
desc "Database backup"
task backup: :environment do
# ...
end
end
.rake
files
If your list of Rake tasks is growing, you may want to split them per categories in several files:
$ mkdir -p rakelib
# rakelib/catalog.rake
namespace :catalog do
desc "Export the entire catalog"
task export: :environment do
# ...
end
end
List your tasks
Here’s how to list your Rake tasks:
$ bundle exec rake -T
rake catalog:export # Export the entire catalog
rake db:backup # Database backup
rake environment # Load the full project
rake spec # Run RSpec code examples