Object
The format class knows the guts of the RubyGem .gem file format and provides the capability to read gem files
Reads the named gem file and returns a Format object, representing the data from the gem file
| file_path |
|
# 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
Reads a gem from an io stream and returns a Format object, representing the data from the gem file
| io |
|
# 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
Constructs an instance of a Format object, representing the gem’s data structure.
| 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
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 |
|
# 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
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 |
|
# 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
Reads lines from the supplied IO until a end-of-yaml (—) is reached
| file |
|
| block |
|
# 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
Skips the Ruby self-install header. After calling this method, the IO index will be set after the Ruby code.
| file |
|
# 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.
Generated with the Darkfish Rdoc Generator 1.1.6.