diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-10 07:48:56 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-10 07:48:56 +0000 |
commit | fbf59bdbea63efd34ccc144e648467d2f52e7345 (patch) | |
tree | 244f0e7ae112cc7dd135e5d1ac24e6c70ba71b4a /lib/rubygems/indexer/quick_index_builder.rb | |
parent | 7a4aad75356496559460041a6c063bdb736c7236 (diff) | |
download | ruby-fbf59bdbea63efd34ccc144e648467d2f52e7345.tar.gz |
Import RubyGems trunk revision 1493.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/indexer/quick_index_builder.rb')
-rw-r--r-- | lib/rubygems/indexer/quick_index_builder.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/rubygems/indexer/quick_index_builder.rb b/lib/rubygems/indexer/quick_index_builder.rb new file mode 100644 index 0000000000..8805f3fe38 --- /dev/null +++ b/lib/rubygems/indexer/quick_index_builder.rb @@ -0,0 +1,48 @@ +require 'rubygems/indexer' + +# Construct a quick index file and all of the individual specs to support +# incremental loading. +class Gem::Indexer::QuickIndexBuilder < Gem::Indexer::AbstractIndexBuilder + + def initialize(filename, directory) + directory = File.join directory, 'quick' + + super filename, directory + end + + def cleanup + super + + quick_index_file = File.join(@directory, @filename) + compress quick_index_file + + # the complete quick index is in a directory, so move it as a whole + @files.delete quick_index_file + @files << @directory + end + + def add(spec) + @file.puts spec.full_name + add_yaml(spec) + add_marshal(spec) + end + + def add_yaml(spec) + fn = File.join @directory, "#{spec.full_name}.gemspec.rz" + zipped = zip spec.to_yaml + File.open fn, "wb" do |gsfile| gsfile.write zipped end + end + + def add_marshal(spec) + # HACK why does this not work in #initialize? + FileUtils.mkdir_p File.join(@directory, "Marshal.#{Gem.marshal_version}") + + fn = File.join @directory, "Marshal.#{Gem.marshal_version}", + "#{spec.full_name}.gemspec.rz" + + zipped = zip Marshal.dump(spec) + File.open fn, "wb" do |gsfile| gsfile.write zipped end + end + +end + |