Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Rake Task Management Essentials

You're reading from   Rake Task Management Essentials Deploy, test, and build software to solve real-world automation challenges using Rake.

Arrow left icon
Product type Paperback
Published in Apr 2014
Publisher
ISBN-13 9781783280773
Length 122 pages
Edition Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Andrey Koleshko Andrey Koleshko
Author Profile Icon Andrey Koleshko
Andrey Koleshko
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Rake Task Management Essentials
Credits
About the Author
Acknowledgements
About the Reviewers
www.PacktPub.com
Preface
1. The Software Task Management Tool – Rake FREE CHAPTER 2. Working with Files 3. Working with Rules 4. Cleaning Up a Build 5. Running Tasks in Parallel 6. Debugging Rake Tasks 7. Integration with Rails 8. Testing Rake Tasks 9. Continuous Integration 10. Relentless Automation Index

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.

You have been reading a chapter from
Rake Task Management Essentials
Published in: Apr 2014
Publisher:
ISBN-13: 9781783280773
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image