Friday, March 14, 2008

Publish Ruby gems to RubyForge in 10 minutes

What?

A quick tutorial to how to publish your ruby gems to the rubyforge gem listing in just under 10 minutes.

This is a fat-reduced version of nuby on rails' tutorial. Thanks for the great info!

Why?

You want to share your code, right? Sharing your ruby code is *really easy*!

How?

Using hoe. This assumes you already have a rubyforge account and a project approved. See https://rubyforge.org/account/register.php to set up an account and http://rubyforge.org/register/projectinfo.php to register a project.

Setup


sudo gem install hoe --include-dependencies

Set your environment EDITOR variable, if you haven't already. Edit ~/.profile or ~/.bash_login or equivelant, and put in

# ~/.bash_login
export EDITOR=/usr/bin/mate -w

Set up your computer to be able to talk to rubyforge. This will open a configuration file in your editor. Change the username and email

rubyforge setup
Log in to rubyforge

rubyforge login
Sow your project

For a project registered with rubygorge as object-stash you would do:

sow object-stash

This creates a directory object-stash with the files:

History.txt
Manifest.txt
Rakefile
README.txt
bin
sparklines
lib
sparklines.rb
test
test_sparklines.rb

It will list in the command line what you need to fix in the auto generated files.

*Note* If your project name contains a dash - you will have to fix the the class name from "Object-stash" to ObjectStash in lib/object-stash.rb and Rakefile. A shortcoming of hoe, but a minor one.

If you want to auto-publish your documentation to the project main site, e.g. http://object-stash.rubyforge.org/, then edit Rakefile and add:


p.remote_rdoc_dir = '' # Release to root

Write your code

Add and edit files in lib

Release

Run


rake check_manifest


to make sure your Manifest file is correct. The lines with a - are listed in the Manifest but don’t exist on disk. The lines with a + are not in the Manifest but are on the disk.

*Note* Make sure the file ends with at least one blank line!

Now edit History.txt

== 1.0.1

* New version
* Features


Update the version number in your ruby class files:

# lib/object-stash.rb
class ObjectStash
VERSION = '1.0.1'
end
Release!


rake release VERSION=1.0.1

Publish your docs!

rake publish_docs

View docs and install your gem remotely

Go to your project's base url to view the docs, e.g. http://object-stash.rubyforge.org/.

Install your own gem! As easy as 1, 2,

sudo gem install object-stash

No comments: