Sunday, August 15, 2010

Examining .gem files

The gem(1) utility has a lot of useful commands for managing gem repositories. It only provides two commands for manipulating .gem files, however: build and install.

When building your own gems, or examining a gem before install, it is useful to be able to take a look at the contents without extracting the gem to a temporary directory.

The structure of the gem is simple: a tar file containing a tarball of the gem contents, and a compressed file containing the metadata:

bash# tar -tf /tmp/test.gem
tar: Record size = 19 blocks
data.tar.gz
metadata.gz

Both tar and gzip support input and output on STDOUT, so it is easy enough to write shell functions to access the contents and metadata:

gem_contents () {
  tar -xOf $1 data.tar.gz | tar -ztf -
  return $?
}

gem_metadata () {
  tar -xOf $1 metadata.gz | gzip -d
  return $?
}

This provides quick access to the contents and metadata of a gem file:

gem_contents /tmp/test.gem
gem_metatdata /tmp/test.gem

No comments:

Post a Comment