1. Computing

Creating and Distributing Gems with Bundler

By

3 of 6

Generating the Project Directory
Creating and Distributing Gems with Bundler

You can then generate a project directory using the bundle gem gemname command.

$ bundle gem awesome_gem

This command did a few things. First, it made the awesome_gem directory. Second, it put the most important file in place, the awesome_gem.gemspec file. This gemspec file defines all of the meta-data for the gem. Its name, author, author's email, version, etc. We'll get back to this file in a moment.

The command also initialized a Git repository. At this stage, before you write or import any code, it's a good idea to set up a matching repository on Github.com and add the Github external. Also, make sure you have your Rubygems.org account set up so you'll be able to publish your gems easily.

The bundle command also generated a Rakefile. This Rakefile is where you'll package and publish your gem. If you look in this file, you'll see that the actual tasks are buried in Bundler's code, but you can run a quick rake -T to get a list of tasks.


$ rake -T
(in /Users/uzimonkey/awesome_gem)
rake build    # Build awesome_gem-0.0.1.gem into the pkg directory
rake install  # Build and install awesome_gem-0.0.1.gem into system gems
rake release  # Create tag v0.0.1 and build and push awesome_gem-0.0.1.gem ...

Pretty simple interface. There's a build task, that will build the gem and store it in the pkg directory. There's also an install task, which will build and install the gem onto your system. This is particularly useful if you want to manage your own software using gems, but not upload to RubyGems or set up your own repository, or just for testing purposes. Finally, there's the release task. This is the most powerful of the tasks, as it'll automatically tag the release in Git, push to GitHub and to RubyGems.org. With a single command, you'll be releasing your gems to the public in two ways.

  1. About.com
  2. Computing
  3. Ruby
  4. Advanced Ruby
  5. Generating the Project Directory

©2014 About.com. All rights reserved.