- Rake Task Management Essentials
- Andrey Koleshko
- 256字
- 2021-07-16 12:01:41
Defining custom rake tasks
So far, we defined only one task named default
. Rake allows you to define your custom tasks with any name. The common form of the custom rake task definition is passing a task name to the task
method and a block as a second argument. The block defines some action and usually contains some Ruby code. The rake task might have an optional description, which is defined with the desc
method. This method accepts a text for the description of the task. The following code snippet is an example of defining a custom rake task:
desc 'Restart web server' task :restart do touch '~/restart.txt' end
This is an example of a possible rake task to restart Passenger (this is a module for the Nginx web server, which works with the Rails applications). We name the task restart
. To run this task, just pass its name as the second argument to the rake
command as shown in the following line of code:
$ rake restart
If you have a lot of tasks, it's handy to enclose them to the named spaces, as shown in the following code snippet:
namespace :server do desc 'Restart web server' task :restart do touch './tmp/restart.txt' end end
You can also run the task in the command line using the following command:
$ rake server:restart
Actually, the task method accepts more arguments. However, they are related to other topics that are explained further along in the book in Chapter 2, Working with Files, and Chapter 3, Working with Rules.
- 玩轉(zhuǎn)Scratch少兒趣味編程
- 圖解Java數(shù)據(jù)結(jié)構(gòu)與算法(微課視頻版)
- Vue.js入門與商城開發(fā)實(shí)戰(zhàn)
- Learning Data Mining with Python
- MySQL數(shù)據(jù)庫(kù)管理與開發(fā)實(shí)踐教程 (清華電腦學(xué)堂)
- SQL基礎(chǔ)教程(視頻教學(xué)版)
- Nginx實(shí)戰(zhàn):基于Lua語(yǔ)言的配置、開發(fā)與架構(gòu)詳解
- 移動(dòng)增值應(yīng)用開發(fā)技術(shù)導(dǎo)論
- QGIS 2 Cookbook
- C語(yǔ)言程序設(shè)計(jì)
- 30天學(xué)通C#項(xiàng)目案例開發(fā)
- Mastering ASP.NET Core 2.0
- Clojure Web Development Essentials
- Bitcoin Essentials
- Zend Framework 2 Cookbook