The RubyGems Package Manager
When you run code locally, it is possible to take a lot of things for granted. You can use various tricks to hack Ruby’s loadpath from the command line, count on certain packages being installed, and otherwise introduce dependencies on the particular configuration of your machine.
RubyGems provides a way to help mitigate all these concerns, in the form of a full-blown package management system. I assume that everyone who is reading this book is familiar with installing software from gems, but has not necessarily managed their own gems before. Knowing how to build your own packages can be useful, whether you’re distributing open source code or just sharing packages within an organization, so we’ll focus on that aspect here.
Writing a Gem::Specification
A gem specification (or gemspec) is essentially a project manifest with some special metadata that is used at package install time. The easiest way to describe how to build a gemspec is by working through a real example of one. As we’ve had good luck so far with looking at how Haml does things, we can turn to it yet again without being disappointed:
require 'rubygems' require 'rake' HAML_GEMSPEC = Gem::Specification.new do |spec| spec.name = 'haml' spec.rubyforge_project = 'haml' spec.summary = "An elegant, structured XHTML/XML templating engine. " + "Comes with Sass, a similar CSS templating engine." spec.version = File.read('VERSION').strip spec.authors = ['Nathan Weizenbaum', 'Hampton Catlin'] spec.email ...
Get Ruby Best Practices now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.