Preface
Maybe every Ruby developer who is familiar with Rails knows what Rake is. However, many of them are unaware of the complete power of this tool and its real aim. The goal of this book is to improve this situation.
Have you ever had to perform boring, repetitive tasks while deploying your project? I assume here that a project is not only something written in Ruby or another programming language, but it can also consist of operations with files. For example, it might be a book or the documentation of a project that you are writing in Markdown and then compiling into HTML. Or it can be compiling a lot of files to one package. Have you ever wished to build a project or run tests on a project whenever it undergoes a change? All this stuff is easily made possible by programs called software management tools. Rake is one such program.
Rake was initially implemented as a Ruby version of Make—a commonly used build utility. However, calling Rake a build utility undermines its true power. Rake is actually an automation tool—it's a way to put all those tasks that you perform under the project into one neat and tidy place.
Basically, build automation includes the following processes:
Compiling the computer source code into binary code
Packaging the binary code
Running tests
Deployment to production systems
Creating documentation and/or release notes
Rake can be used in all these situations, and this book shows you how Rake performs all the steps. After reading this book, you will know Rake better and be able to write more clear and robust Rake code.
What this book covers
Chapter 1, The Software Task Management Tool – Rake, introduces you to the basic usage of Rake and its command-line utilities. You will learn what a rake task is and how to set dependencies between rake tasks, what a default rake task is, Rakefile
, and the global Rakefile
. This chapter also contains information about the Rake project structure and how to organize the code.
Chapter 2, Working with Files, explains the foundational features of Rake that help us work with files. This is mandatory information because of Rake's orientation—it is built to be an automation tool. You will see that there is a special rake task for file processing called file
. The main part of the chapter contains the explanation of utilities that are offered by Rake to work with the files: FileList
and FileUtils
. At the end, you will be given a real-world example on how to apply the acquired knowledge.
Chapter 3, Working with Rules, will show how knowing a rule
task may allow you to write more robust and precise code.
Chapter 4, Cleaning Up a Build, describes one of the useful features of Rake—the capability to clean the build of your project with the clean
standard task.
Chapter 5, Running Tasks in Parallel, helps us figure out how to speed up the resulting task execution with multitask
. We will learn which basic problems may arise while implementing parallelism and how to avoid them.
Chapter 6, Debugging Rake Tasks, provides the basic knowledge to debug Rake projects. You will be provided with an example on how to debug rake tasks inherent to Rake techniques and also to Ruby projects in general.
Chapter 7, Integration with Rails, provides an overview of how Rake is integrated into the famous Ruby web framework, Rails. The chapter shows how to write custom rake tasks in a Rails project and run them manually or automatically on schedule.
Chapter 8, Testing Rake Tasks, details the reasons we should test rake tasks. Also, you will see an example of how to write the tests with MiniTest—a built-in Ruby test framework.
Chapter 9, Continuous Integration, briefly introduces you to Jenkins—a continuous integration software. You will see how to configure it and run rake tasks with its help.
Chapter 10, Relentless Automation, doesn't introduce any new Rake terms, but you will find useful examples of the Rake appliance by popular programs. You will be introduced to the Thor utility, which can replace Rake in some circumstances. Then we will compare both of these frameworks. Finally, we will briefly gather all the information that was provided throughout the book.
What you need for this book
To run the examples in this book, you must have Ruby installed. The examples can be run in all operation systems where Ruby can be installed. However, a few chapters provide examples that may be run only on Unix-based systems such as Linux and OS X. The command-line examples are written in a Unix-like style, but Windows users will also be able to run them.
Who this book is for
This book requires basic knowledge of Ruby because Rake is written in this programming language. But it doesn't mean that gurus of other languages will not be able to understand the examples. If you are working with a build automation tool that doesn't fit your requirements or seems too complicated, this book is what you need.
Conventions
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include
directive."
A block of code is set as follows:
task :hello do puts 'Hello, Rake!' end
Any command-line input is written as follows:
$ rake task2
All command-line outputs have been highlighted and will appear as follows:
rake aborted! this is an error
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "You will be redirected to the configuration page of the created project. There you will find the Build section with the Add build step dropdown."
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <feedback@packtpub.com>
, and mention the book title via the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <copyright@packtpub.com>
with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
Questions
You can contact us at <questions@packtpub.com>
if you are having a problem with any aspect of the book, and we will do our best to address it.