How to Write Rake Tasks
Rake is an open-source-supported project t used for building applications. It is used by Ruby developers who want to compile their code into usable applications without having to use Ruby's native Makefile compiler. Rake allows Ruby developers to create custom automated build systems that link and compile their code, saving them time and identifying unmet dependencies in the application structure. This tutorial will show you how to write a simple "Hello World" rake task that compiles a small bit of code and executes it to display the term "Hello World".
Instructions
-
-
1
Open a text editor such as Notepad (included with Microsoft Windows) or Text Edit (included with Mac OS X). Create a blank text document used to write the rake codes.
-
2
Create a temporary directory for the task by writing your first line of the rake task as:
directory "tmp"
-
-
3
Write the rest of the rake task by specifying a file and what task should be done with it. In this case, we'll be take a temporary file from the "tmp" directory" and making it display text. The code for this example would read as follows:
file "hello.tmp" => "tmp" do
sh "echo 'Hello World' >> 'tmp/hello.tmp'"
end
-
4
Save the text file for future reference and copy and paste the code into a command line utility when connected to your Web server to execute the task.
-
1