Geminstaller C0 Coverage Information - RCov

spec/fixture/rubygems_dist/rubygems-trunk/lib/rubygems/package/tar_output.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
spec/fixture/rubygems_dist/rubygems-trunk/lib/rubygems/package/tar_output.rb 144 70
43.06%
10.00%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 # -*- coding: utf-8 -*-
2 #--
3 # Copyright (C) 2004 Mauricio Julio Fernández Pradier
4 # See LICENSE.txt for additional licensing information.
5 #++
6 
7 ##
8 # TarOutput is a wrapper to TarWriter that builds gem-format tar file.
9 #
10 # Gem-format tar files contain the following files:
11 # [data.tar.gz] A gzipped tar file containing the files that compose the gem
12 #               which will be extracted into the gem/ dir on installation.
13 # [metadata.gz] A YAML format Gem::Specification.
14 # [data.tar.gz.sig] A signature for the gem's data.tar.gz.
15 # [metadata.gz.sig] A signature for the gem's metadata.gz.
16 #
17 # See TarOutput::open for usage details.
18 
19 class Gem::Package::TarOutput
20 
21   ##
22   # Creates a new TarOutput which will yield a TarWriter object for the
23   # data.tar.gz portion of a gem-format tar file.
24   #
25   # See #initialize for details on +io+ and +signer+.
26   #
27   # See #add_gem_contents for details on adding metadata to the tar file.
28 
29   def self.open(io, signer = nil, &block) # :yield: data_tar_writer
30     tar_outputter = new io, signer
31     tar_outputter.add_gem_contents(&block)
32     tar_outputter.add_metadata
33     tar_outputter.add_signatures
34 
35   ensure
36     tar_outputter.close
37   end
38 
39   ##
40   # Creates a new TarOutput that will write a gem-format tar file to +io+.  If
41   # +signer+ is given, the data.tar.gz and metadata.gz will be signed and
42   # the signatures will be added to the tar file.
43 
44   def initialize(io, signer)
45     @io = io
46     @signer = signer
47 
48     @tar_writer = Gem::Package::TarWriter.new @io
49 
50     @metadata = nil
51 
52     @data_signature = nil
53     @meta_signature = nil
54   end
55 
56   ##
57   # Yields a TarWriter for the data.tar.gz inside a gem-format tar file.
58   # The yielded TarWriter has been extended with a #metadata= method for
59   # attaching a YAML format Gem::Specification which will be written by
60   # add_metadata.
61 
62   def add_gem_contents
63     @tar_writer.add_file "data.tar.gz", 0644 do |inner|
64       sio = @signer ? StringIO.new : nil
65       Zlib::GzipWriter.wrap(sio || inner) do |os|
66 
67         Gem::Package::TarWriter.new os do |data_tar_writer|
68           # :stopdoc:
69           def data_tar_writer.metadata() @metadata end
70           def data_tar_writer.metadata=(metadata) @metadata = metadata end
71           # :startdoc:
72 
73           yield data_tar_writer
74 
75           @metadata = data_tar_writer.metadata
76         end
77       end
78 
79       # if we have a signing key, then sign the data
80       # digest and return the signature
81       if @signer then
82         digest = Gem::Security::OPT[:dgst_algo].digest sio.string
83         @data_signature = @signer.sign digest
84         inner.write sio.string
85       end
86     end
87 
88     self
89   end
90 
91   ##
92   # Adds metadata.gz to the gem-format tar file which was saved from a
93   # previous #add_gem_contents call.
94 
95   def add_metadata
96     return if @metadata.nil?
97 
98     @tar_writer.add_file "metadata.gz", 0644 do |io|
99       begin
100         sio = @signer ? StringIO.new : nil
101         gzos = Zlib::GzipWriter.new(sio || io)
102         gzos.write @metadata
103       ensure
104         gzos.flush
105         gzos.finish
106 
107         # if we have a signing key, then sign the metadata digest and return
108         # the signature
109         if @signer then
110           digest = Gem::Security::OPT[:dgst_algo].digest sio.string
111           @meta_signature = @signer.sign digest
112           io.write sio.string
113         end
114       end
115     end
116   end
117 
118   ##
119   # Adds data.tar.gz.sig and metadata.gz.sig to the gem-format tar files if
120   # a Gem::Security::Signer was sent to initialize.
121 
122   def add_signatures
123     if @data_signature then
124       @tar_writer.add_file 'data.tar.gz.sig', 0644 do |io|
125         io.write @data_signature
126       end
127     end
128 
129     if @meta_signature then
130       @tar_writer.add_file 'metadata.gz.sig', 0644 do |io|
131         io.write @meta_signature
132       end
133     end
134   end
135 
136   ##
137   # Closes the TarOutput.
138 
139   def close
140     @tar_writer.close
141   end
142 
143 end
144 

Generated on Mon May 10 23:40:28 -0700 2010 with rcov 0.9.8