Parent

Class Index [+]

Quicksearch

Gem::OldFormat

The format class knows the guts of the RubyGem .gem file format and provides the capability to read gem files

Attributes

spec[RW]
file_entries[RW]
gem_path[RW]

Public Class Methods

from_file_by_path(file_path) click to toggle source

Reads the named gem file and returns a Format object, representing the data from the gem file

file_path
String

Path to the gem file

    # File lib/rubygems/old_format.rb, line 36
36:   def self.from_file_by_path(file_path)
37:     unless File.exist?(file_path)
38:       raise Gem::Exception, "Cannot load gem file [#{file_path}]"
39:     end
40: 
41:     File.open(file_path, 'rb') do |file|
42:       from_io(file, file_path)
43:     end
44:   end
from_io(io, gem_path="(io)") click to toggle source

Reads a gem from an io stream and returns a Format object, representing the data from the gem file

io
IO

Stream from which to read the gem

    # File lib/rubygems/old_format.rb, line 52
52:   def self.from_io(io, gem_path="(io)")
53:     format = self.new(gem_path)
54:     skip_ruby(io)
55:     format.spec = read_spec(io)
56:     format.file_entries = []
57:     read_files_from_gem(io) do |entry, file_data|
58:       format.file_entries << [entry, file_data]
59:     end
60:     format
61:   end
new(gem_path) click to toggle source

Constructs an instance of a Format object, representing the gem’s data structure.

gem
String

The file name of the gem

    # File lib/rubygems/old_format.rb, line 26
26:   def initialize(gem_path)
27:     @gem_path = gem_path
28:   end

Private Class Methods

read_files_from_gem(gem_file) click to toggle source

Reads the embedded file data from a gem file, yielding an entry containing metadata about the file and the file contents themselves for each file that’s archived in the gem. NOTE: Many of these methods should be extracted into some kind of Gem file read/writer

gem_file
IO

The IO to process

     # File lib/rubygems/old_format.rb, line 129
129:   def self.read_files_from_gem(gem_file)
130:     errstr = "Error reading files from gem"
131:     header_yaml = ''
132:     begin
133:       self.read_until_dashes(gem_file) do |line|
134:         header_yaml << line
135:       end
136:       header = YAML.load(header_yaml)
137:       raise Gem::Exception, errstr unless header
138: 
139:       header.each do |entry|
140:         file_data = ''
141:         self.read_until_dashes(gem_file) do |line|
142:           file_data << line
143:         end
144:         yield [entry, Zlib::Inflate.inflate(file_data.strip.unpack("m")[0])]
145:       end
146:     rescue Zlib::DataError => e
147:       raise Gem::Exception, errstr
148:     end
149:   end
read_spec(file) click to toggle source

Reads the specification YAML from the supplied IO and constructs a Gem::Specification from it. After calling this method, the IO index will be set after the specification header.

file
IO

The IO to process

     # File lib/rubygems/old_format.rb, line 93
 93:   def self.read_spec(file)
 94:     yaml = ''
 95: 
 96:     read_until_dashes file do |line|
 97:       yaml << line
 98:     end
 99: 
100:     Gem::Specification.from_yaml yaml
101:   rescue YAML::Error => e
102:     raise Gem::Exception, "Failed to parse gem specification out of gem file"
103:   rescue ArgumentError => e
104:     raise Gem::Exception, "Failed to parse gem specification out of gem file"
105:   end
read_until_dashes(file) click to toggle source

Reads lines from the supplied IO until a end-of-yaml (—) is reached

file
IO

The IO to process

block
String

The read line

     # File lib/rubygems/old_format.rb, line 114
114:   def self.read_until_dashes(file)
115:     while((line = file.gets) && line.chomp.strip != "---") do
116:       yield line
117:     end
118:   end
skip_ruby(file) click to toggle source

Skips the Ruby self-install header. After calling this method, the IO index will be set after the Ruby code.

file
IO

The IO to process (skip the Ruby code)

    # File lib/rubygems/old_format.rb, line 71
71:   def self.skip_ruby(file)
72:     end_seen = false
73:     loop {
74:       line = file.gets
75:       if(line == nil || line.chomp == "__END__") then
76:         end_seen = true
77:         break
78:       end
79:     }
80: 
81:     if end_seen == false then
82:       raise Gem::Exception.new("Failed to find end of ruby script while reading gem")
83:     end
84:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.