summaryrefslogtreecommitdiff
path: root/lib/rubygems/indexer/quick_index_builder.rb
blob: dc36179dc5b1f2a9a8c9e7c15d00b8e18b4d2637 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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 'index'
    @files << 'quick'
  end

  def add(spec)
    @file.puts spec.original_name
    add_yaml(spec)
    add_marshal(spec)
  end

  def add_yaml(spec)
    fn = File.join @directory, "#{spec.original_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.original_name}.gemspec.rz"

    zipped = zip Marshal.dump(spec)
    File.open fn, "wb" do |gsfile| gsfile.write zipped end
  end

end