Class Gem::Indexer::AbstractIndexBuilder
In: lib/rubygems/indexer/abstract_index_builder.rb
Parent: Object

Abstract base class for building gem indicies. Uses the template pattern with subclass specialization in the begin_index, end_index and cleanup methods.

Methods

build   cleanup   compress   end_index   new   start_index   unzip   zip  

Attributes

directory  [R]  Directory to put index files in
filename  [R]  File name of the generated index
files  [R]  List of written files/directories to move into production

Public Class methods

[Source]

    # File lib/rubygems/indexer/abstract_index_builder.rb, line 19
19:   def initialize(filename, directory)
20:     @filename = filename
21:     @directory = directory
22:     @files = []
23:   end

Public Instance methods

Build a Gem index. Yields to block to handle the details of the actual building. Calls begin_index, end_index and cleanup at appropriate times to customize basic operations.

[Source]

    # File lib/rubygems/indexer/abstract_index_builder.rb, line 30
30:   def build
31:     FileUtils.mkdir_p @directory unless File.exist? @directory
32:     raise "not a directory: #{@directory}" unless File.directory? @directory
33: 
34:     file_path = File.join @directory, @filename
35: 
36:     @files << @filename
37: 
38:     File.open file_path, "wb" do |file|
39:       @file = file
40:       start_index
41:       yield
42:       end_index
43:     end
44: 
45:     cleanup
46:   ensure
47:     @file = nil
48:   end

Called from within builder after the index file has been closed.

[Source]

    # File lib/rubygems/indexer/abstract_index_builder.rb, line 74
74:   def cleanup
75:   end

Compress the given file.

[Source]

    # File lib/rubygems/indexer/abstract_index_builder.rb, line 53
53:   def compress(filename, ext="rz")
54:     data = open filename, 'rb' do |fp| fp.read end
55: 
56:     zipped = zip data
57: 
58:     File.open "#{filename}.#{ext}", "wb" do |file|
59:       file.write zipped
60:     end
61:   end

Called immediately after the yield in build. The index file is still open and available as @file.

[Source]

    # File lib/rubygems/indexer/abstract_index_builder.rb, line 70
70:   def end_index
71:   end

Called immediately before the yield in build. The index file is open and available as @file.

[Source]

    # File lib/rubygems/indexer/abstract_index_builder.rb, line 65
65:   def start_index
66:   end

Return an uncompressed version of a compressed string.

[Source]

    # File lib/rubygems/indexer/abstract_index_builder.rb, line 78
78:   def unzip(string)
79:     Zlib::Inflate.inflate(string)
80:   end

Return a compressed version of the given string.

[Source]

    # File lib/rubygems/indexer/abstract_index_builder.rb, line 83
83:   def zip(string)
84:     Zlib::Deflate.deflate(string)
85:   end

[Validate]