For my next assignment with the time logger application I have been exploring and learning about Rake. Rake is a build language and it is also a Domain Specific Language (DSL). It executes tasks
in a dependency way (ex: do this first then that). One way to use it is when you need setup for your program before running it. For example, in my assignment I need to create a database table and schema before the user can start using the program. This way when they log their time, data will be saved in a Postgresql database. The unique part about Rake is the fact that Ruby code can be written directly in a Rakefile. This differs significantly from other build languages. To use it on your project you must install the rake gem.
Here’s an example. Lets say you want to cook a recipe. Recipes have specific instructions that must be followed in order.
You can run a Rakefile through the command line by running rake <task_name>
avnikothari@Avnis-MacBook-Air:~$ rake cook_food
I took out the vegetables from my refridgeator
I cut the vegetables
I sauted the veggies
I mixed in the sauce
the meal is ready
task
specifies that we want it to execute the part inside the do
and end
blocks. The symbol =>
denotes the fact that there is a depedency on that specfic task. So it will not execute that task before executing the dependency, and multiple dependencies can be written in square brackets like this
When we run rake cook_food
we will receive the same output as above.
Rake tasks can also be namespaced for organizational purposes. Like this
We would then run rake recipe::cook_food
to have to same output as above.