Over the weekend I created my first ruby gem for some internal code I've been prototyping at work. I was surprised how easy it is to create the gem, particularly via Rake, the Ruby build tool.
All you need to do is add a ruby gem specification to your Rakefile and a task definition and you're done:
spec = Gem::Specification.new do |s|
s.name = "Name"
s.version = "0.0.1"
s.author = "Marcus Crafter"
s.email = "crafterm@gmail.com"
s.homepage = "http://blogs.cocoondev.org/crafterm/"
s.platform = Gem::Platform::RUBY
s.summary = "Some description"
s.files = FileList["{bin,lib}/**/*"].to_a
s.require_path = "lib"
s.autorequire = "name"
s.test_files = FileList["{test}/**/*test.rb"].to_a
s.has_rdoc = true
s.extra_rdoc_files = ["README"]
s.add_dependency("dependency", ">= 0.x.x")
end
Rake::GemPackageTask.new(spec) do |pkg|
pkg.need_tar = true
end
Then a:
$> rake gem
will build a package for you in a pkg subdirectory ready for deployment, installation, etc.
In addition to this there's nice support for building ruby extensions upon gem installation, and also non-ruby cod, upon other things.
The only unusual thing for a Java developer is that source for gems by convention go into the lib directory rather than src.
Useful links in this area are the Gemspec reference, this article on linuxjournal, and also chapter 17 from the Ruby Book which I found most valuable.
Posted by crafterm at July 31, 2006 02:59 AM | TrackBack