Research
- What is
rake
good for? - Take a look at some of the Rake tasks that Rails gives you (
rake -T
within a Rails project) - Find the code that defines the
rake stats
task in the Rails gems - What are some ways how a Rake task can execute another task?
- What does it mean if a Rake task "depends" on another task? E.g. understand what it means for a Rake task within a Rails app to depend on
:environment
. - Understand that Capistrano tasks are also defined using the Rake DSL, but a Capistrano task is not automatically a Rake task and vice versa.
Exercises
- Write a Rake task
rake list_app_files
that lists all Ruby files and their file size within theapp
directory.- Hint: Use globbing to find those files (
Dir.glob(File.join('root_directory', '**', '*.rb'))
) - Hint: You could use the number_to_human_size Show archive.org snapshot helper for better file size formatting
- Hint: For better testability, write a service class with the functionality and only call it in your rake task
- Hint: Use globbing to find those files (
- Use a namespace to rename your task to
rake app:list_files
- Give your task a nice description and notice how it appears in
rake -T
Posted by Henning Koch to makandra Curriculum (2015-08-21 09:38)