I use jeweler for my gems. The use of gems like jeweler or hoe for gem development is a much debated topic, but it was pretty easy maintaining gems with jeweler.
Here's a simple demo .
First install jeweler : gem install jeweler
It's very important to print "Hello World" in many projects. So we'll make a gem for that.
First, you'll have to create a repo on GitHub with the gem name, here, 'hello_world'. Once that's done, we'll use jeweler to create a skeleton of the gem.
jeweler hello_world --rspec --github-username emilsoman --github-token any_random_string
This will create the gem directory
hello_world where your gem lives. You can also see that
the directory is now a git repo and the code has been pushed to GitHub.
git remove -v email@example.com:emilsoman/contractor.git (fetch) firstname.lastname@example.org:emilsoman/contractor.git (push)
--github-token anyrandomstring is not used anymore, but jeweler still requires it as a mandatory option. This is a bug in jeweler. So we'll just provide some random string there.
UPDATE: I've fixed this issue in my fork of jeweler. You do not have to provide the random github token if you use this fix.
Next step is to add some details to the gem. Open up Rakefile where jeweler keeps the details that would be placed later in hello_world.gemspec. Add a
description for the gem.
Open up Gemfile, remove the spermy operator for rspec and bundler, we can use the latest versions.
Also , I'm not using rcov, so I'm removing that gem from the Gemfile.
bundle install to resolve dependencies.
Now we're ready to write the gem. Notice the
lib/hello_world.rb file ? That's the file that
gets required when you require the gem using
require 'hello_world'. So that's where we'll put this code :
Now stage the changes. Write a version file, and release the gem. You need an account with RubyGems.org to release the gem there. git add . rake version:write rake release
Our super important hello_world gem is official now and ready to be used by millions across the world.
The gem release workflow using jeweler would be typically as follows:
- Bump version using rake version:bump:
. Refer this spec for more info on versioning.
- Make all your changes and commit to repo. Update CHANGELOG for all the changes
- Repeat step 2 till release is ready.
- Before release, review changes and version
By the way , jeweler can do a few more things than that. Run
rake -T inside the gem directory to see everything jeweler can do.