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 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
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 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
Constructs an instance of a Format object, representing the gem’s data structure.
gem |
|
# File lib/rubygems/old_format.rb, line 26 26: def initialize(gem_path) 27: @gem_path = gem_path 28: 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 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
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 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
Reads lines from the supplied IO until a end-of-yaml (—) is reached
file |
|
block |
|
# 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
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 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.
Generated with the Darkfish Rdoc Generator 1.1.6.