GemKata - The Art of the Gem

09 Oct 2009

The dust has settled. The GitHub has moved. What's that you say? They don't build gems anymore? Don't worry, you should use GemCutter. This assumes that you are already using jeweler. You are, aren't you?

Let's say you want to release a gem

Make sure your jeweler config in your Rakefile looks something like the following.

  require 'jeweler'
  Jeweler::Tasks.new do |gem|
    gem.name = "your-awesome-gem-here"
    # ...
rescue LoadError
  puts "Jeweler not available. Install it with: gem install jeweler"

Now it's as easy as typing:

# If you have never released before
rake version write MAJOR=0 MINOR=1 PATCH=0
# If you are back for more, releasing again
rake version:bump:(major|minor|patch)

You now have an updated gemspec, and with the version set correctly. Now to tag the release on github.

rake release

Finally, release it to GemCutter using:

rake gemcutter:release 

The users are at the gates, and they demand documentation!

The next most awesome thing to do is to add sdoc. Think the best rdoc template in the history of the universe. And as a special bonus we'll generate them on your gh-pages branch so you can go to http://yournamehere.github.com/your-awesome-gem-here to see the rdoc documentation.

Open your Rakefile back up and put this at the bottom:

  %w{sdoc sdoc-helpers rdiscount}.each { |name| gem name }
  require 'sdoc_helpers'
rescue LoadError => ex
  puts "sdoc support not enabled:"
  puts ex.inspect

require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
  version = File.exist?('VERSION') ? File.read('VERSION') : ''
  rdoc.rdoc_dir = 'rdoc'
  rdoc.title = "your-awesome-gem-here #{version}"

To generate the docs the first time run:

rake pages:init

To rebuild the github pages branch after updates:

rake pages

Bask in your amazingness

Now you've done it! You're the envy of ever ne'er-do-well programmer from here to there. Enjoy!

Please wait while my tweets load...

If you can't wait - check out what I've been twittering