How You Fake a Gem Server #
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.
Jim
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.
why
Why not learn to script Gems, though? Really, this can be extended by my own hands, Jim.
why
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.Dave Burt
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?
Chad
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.
Chad
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.
why
Okay, there ya have it.
Comments are closed for this entry.