hoodwink.d enhanced
RSS
2.0
XHTML
1.0

RedHanded

How You Fake a Gem Server #

by why in bits

It’s odd that RubyGems doesn’t serve its own docs. See gem_server for yourself. In fact, where are the pro-grade gem docs?

 require 'rubygems/format'
 GEM_SERVER_DIR = "/var/www/htdocs" 
 specs =
   Dir[GEM_SERVER_DIR + "/gems/*.gem"].inject({}) do |hsh, path|
     name = File.basename(path).sub(/\.gem$/,'')
     hsh.merge name => Gem::Format.from_file_by_path(path).spec
   end
 index = Gem::SourceIndex.new specs
 yaml_write = proc { |f| f.write index.to_yaml }
 File.open(GEM_SERVER_DIR + "/yaml", "w", &yaml_write)
 Zlib::GzipWriter.open(GEM_SERVER_DIR + "/yaml.Z", &yaml_write)

That’s a fake gem server. But you have to make a /var/www/htdocs directory. Then, fill up /var/www/htdocs/gems with the all the gems you want to serve. Put this script in cron and it’ll generate the indices.

The Rails team uses a well-concealed gem_update.sh, but there’s opportunity in the above to to use the gemspecs to create an HTML index as well, which could be snazzy.

said on 29 Mar 2006 at 02:20
said on 29 Mar 2006 at 06:21

Why don’t you use the generate_yaml.rb script that comes with RubyGems to do this? Or, if you really want to be cutting edge, grab the RubyGems CVS head and use the index_gem_repository.rb script (which replaces generate_yaml.rb) to build a gem index that can be incrementally downloaded.

said on 29 Mar 2006 at 09:50

Why not learn to script Gems, though? Really, this can be extended by my own hands, Jim.

said on 29 Mar 2006 at 10:07

Okay, wait, I see what you’re saying about the index_gem_repository.rb script. This builds a lot of little indices. So, what versions of RubyGems supports this? Oh and is the simple yaml/yaml.Z approach going away? You know, if I’m only serving a few gems.

said on 30 Mar 2006 at 15:40

I’m sure I’m not alone in looking forward to this exciting change, Jim! It’ll make getting gems from Rubyforge insanely fast compared to what it is now, right?

said on 30 Mar 2006 at 16:09

why, Rubygems from CVS supports the new index style but we’ll also continue to suppor the full-index model. The first release to support the new index style will be 0.9.0.

said on 30 Mar 2006 at 16:34

why, Rubygems from CVS supports the new index style but we’ll also continue to suppor the full-index model. The first release to support the new index style will be 0.9.0.

said on 07 Apr 2006 at 00:10

Okay, there ya have it.

Comments are closed for this entry.