Building Your Own Gem: Adventures in Ruby Programming
I just built my second gem – I thought I’d have written about the first, but somehow it escaped my attention. The first one is already on RubyGems, and generates a seed for you from the Weather Underground API by pulling together a string from some of the weather data on the feed.
When I started writing the second one, I realized that I didn’t remember the very first command I had run to create the gem’s template files – the gemspec, the lib/ and test/ folder, and so on. So here’s a quick round-up of some good tutorials on gem-cutters. I used bundle btw, and here’s a shameless plug: I’ve uploaded a slightly modified set of template files generated from bundle gem, with this one including the requisite files to write tests using minitest.
Links coming soon!
I don’t see why you wouldn’t. It’s easy and it works, and Rails uses it.
Here’s the canonical help page, for using bundle 1)Looks like this is a link to a specific version of bundle (1.5) so if you’re reading this post after a more recent version has been released, then you might need to look for a different URL. to create gems.
Radar Guides to gem development: There’s a great template gem with instructions on what’s going on with Radar Guides. I like this guide because it tells you what’s going with the internals of the gemspec. It’s a much more advanced version of the steps in my template gem.
Some other resources:
- The incomparable RailsCasts episode – #245: New Gem With Bundler – from Mr. Ryan Bates
- A good list of steps from Rake Routes.
- Another good list of steps, a bit more detailed, from Tuts+.
There are other ways of building gems – I’m not sure why. Gems are pretty simple, but I’m guessing the second biggest reason, after “I want to do it my way, because I’m a cool Ruby developer,” is: the other ways integrate differently with publication sources. For example – hoe appears to work with Ruby Forge, whereas bundle works with Ruby Gems.
Here’s what I read – the Ruby on Rails tutorial for hoe, upon which I’m basing my observation above. YMMV.
More “I’m such a precious person” wankery – here’s what the developer thinks about why he needed to write a replacement for bundle (though he’s really only trying to replace hoe, so I should cut him a break) and why I think his reasons are way too precious:
- Only use a Gem::Specification as configuration (bundler does that.)
- Be one command away from version bumping and releasing (don’t bump-and-release so much that having one command for it is necessary, in the first place. Control your ADD.)
- Store version information in one place (bundler does that)
- Only concern itself with git, gems, and versioning (maybe bundler does too much – not sure about that.)
- Not be a requirement for using your Rakefile (you just wouldn’t be able to use its tasks) (yeah, bundler does need a Rakefile, which is a perfectly fine thing!)
- Use Jeweler to manage Jeweler. Oh the meta! (Fuck meta. No, I mean, really, who gives a fuck, except too-precious wankers?)
References [ + ]
|1.||↑||Looks like this is a link to a specific version of bundle (1.5) so if you’re reading this post after a more recent version has been released, then you might need to look for a different URL.|