Class | Gem::Indexer::AbstractIndexBuilder |
In: |
lib/rubygems/indexer/abstract_index_builder.rb
|
Parent: | Object |
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 |
# 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
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.
# 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.
# File lib/rubygems/indexer/abstract_index_builder.rb, line 74 74: def cleanup 75: end
Compress the given file.
# 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
Return an uncompressed version of a compressed string.
# File lib/rubygems/indexer/abstract_index_builder.rb, line 78 78: def unzip(string) 79: Zlib::Inflate.inflate(string) 80: end