Sake - Rake for Your Whole System
Ruby's version of make, Rake, is an indispensable tool that all Rubyists should learn and use regularly. It's the perfect way to run all of those project-specific tasks like clearing the cache or removing stale session data.
Once you start using Rake, you'll probably find that you duplicate many of your tasks in all of your projects. It's not too much to copy often-used .rake files, but there is a better way. Sake (short for System-wide Rake) solves this. Once you install a Rake task into Sake's repository, it becomes available system-wide via the sake command.
Say you have a file named dbversion.rake, which finds the migration version of your database, as follows:
-
namespace :db do
-
desc "Returns the current schema version"
-
task :version => :environment do
-
puts "Current version: " +
-
ActiveRecord::Migrator.current_version.to_s
-
end
-
end
To install this system-wide, first install Sake by running gem install sake. Rubygems will download and install everything for you. Now you can install the Rake task into Sake by typing sake -i dbversion.rake. You can now run the db:version task inside any Rails app by typing sake db:version. Pretty neat, eh?
Sake has a few more tricks up its sleeve. You can view the rake tasks that are currently installed into Sake by running sake -T. It can also install tasks hosted on a remote web server by replacing the filename that appears after sake -i with the url. Check out the original blog post to read more.
Some other sites with info on Rake that I found interesting:
- Some useful Rake tasks from ERR THE BLOG
- A tutorial on Rake from Rails Envy
- A more in-depth view on Rake from Martin Fowler















September 10th, 2007 at 1:49 am
RailsRumble is over, we spend almost 48 hours building http://sakebar.railsrumble.com/ a place where people can sumbit, tags and search for sakes.