3 Ruby Project Time Savers: Hoe 2.0.0, YARD, Whenever
Let's take a look at 3 Ruby tools that help cut down on some of the yak shaving involved in creating and deploying Ruby projects.
The first step in a project's life is the creation: setting up a directory and creating the basic files such as the Rakefile, Gems metadata, and more. Hoe automates all of these steps. After installation (
sudo gem install hoe), creating a project is easy:
creates a new project, directory and all the necessary files, set up with the project name. More importantly, the project's set up with tasks that automate various processes such as building the Gem, pushing it to RubyForge, announce the release, and more. A list of tasks can be seen by running
in the project directory.
Hoe can be configured in the project's Rakefile:
Hoe.new('my_project_name, my_project_name::VERSION) do |p| # config options as Ruby code end
Hoe 2.0.0 was recently released with some improvements, eg. it's now extensible with modules.
After the project's set up it's time to write the code - hopefully with with sufficient documentation. Ruby developers are familiar with RDoc, but a competitor is available with YARD. YARD offers extensibility and Javadoc-style annotations for Ruby code. While development (YARD Github repository) was slow according to its developer, the new release brings some improvements.
One of the changes of the 0.2.3 release is a new way to parse Ruby code. Tools like RDoc or YARD need to parse Ruby code to find out the classes, methods and other aspects in the Ruby source code.
While YARD still uses its home grown Ruby parser on 1.8.x, on Ruby 1.9.x it now uses Ripper to get the AST from Ruby source code. Using Ripper brings more performance and accuracy of the parsing results (writing a complete Ruby parser from scratch takes a while - Ripper provides access to the parse tree used in the Ruby VM).
Finally - when a project's deployed, it can be necessary to set up or modify repeating tasks. The tool of choice, on Unix systems, is
cron. Creating entries in
crontab file them can now be automated with a bit of Ruby code using Whenever.
Whenever is configured using the same approach to embedded DSLs as Rake, Hoe and others. An example from the Whenever Wiki:
every 2.days, :at => '4:30am' do command "/usr/bin/my_great_command" end
is translated to a
30 4 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 * * /usr/bin/my_great_command
The Whenever configuration is more readable and probably easier to modify - even for developers who never got around to understanding the