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 37
37:   def self.from_file_by_path(file_path)
38:     unless File.exist?(file_path)
39:       raise Gem::Exception, "Cannot load gem file [#{file_path}]"
40:     end
41: 
42:     File.open(file_path, 'rb') do |file|
43:       from_io(file, file_path)
44:     end
45:   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 53
53:   def self.from_io(io, gem_path="(io)")
54:     format = self.new(gem_path)
55:     skip_ruby(io)
56:     format.spec = read_spec(io)
57:     format.file_entries = []
58:     read_files_from_gem(io) do |entry, file_data|
59:       format.file_entries << [entry, file_data]
60:     end
61:     format
62:   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 23
23:   def initialize(gem_path)
24:     require 'fileutils'
25:     require 'zlib'
26:     Gem.load_yaml
27: 
28:     @gem_path = gem_path
29:   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 130
130:   def self.read_files_from_gem(gem_file)
131:     errstr = "Error reading files from gem"
132:     header_yaml = ''
133:     begin
134:       self.read_until_dashes(gem_file) do |line|
135:         header_yaml << line
136:       end
137:       header = YAML.load(header_yaml)
138:       raise Gem::Exception, errstr unless header
139: 
140:       header.each do |entry|
141:         file_data = ''
142:         self.read_until_dashes(gem_file) do |line|
143:           file_data << line
144:         end
145:         yield [entry, Zlib::Inflate.inflate(file_data.strip.unpack("m")[0])]
146:       end
147:     rescue Zlib::DataError
148:       raise Gem::Exception, errstr
149:     end
150:   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 94
 94:   def self.read_spec(file)
 95:     yaml = ''
 96: 
 97:     read_until_dashes file do |line|
 98:       yaml << line
 99:     end
100: 
101:     Gem::Specification.from_yaml yaml
102:   rescue YAML::Error => e
103:     raise Gem::Exception, "Failed to parse gem specification out of gem file"
104:   rescue ArgumentError => e
105:     raise Gem::Exception, "Failed to parse gem specification out of gem file"
106:   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 115
115:   def self.read_until_dashes(file)
116:     while((line = file.gets) && line.chomp.strip != "---") do
117:       yield line
118:     end
119:   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 72
72:   def self.skip_ruby(file)
73:     end_seen = false
74:     loop {
75:       line = file.gets
76:       if(line == nil || line.chomp == "__END__") then
77:         end_seen = true
78:         break
79:       end
80:     }
81: 
82:     if end_seen == false then
83:       raise Gem::Exception.new("Failed to find end of ruby script while reading gem")
84:     end
85:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.