Class Gem::Format
In: lib/rubygems/format.rb
Parent: Object

Gem::Format knows the guts of the RubyGem .gem file format and provides the capability to read gem files

Methods

Attributes

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

Public Class methods

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

[Source]

    # File lib/rubygems/format.rb, line 37
37:   def self.from_file_by_path(file_path, security_policy = nil)
38:     format = nil
39: 
40:     unless File.exist?(file_path)
41:       raise Gem::Exception, "Cannot load gem at [#{file_path}] in #{Dir.pwd}"
42:     end
43: 
44:     # check for old version gem
45:     if File.read(file_path, 20).include?("MD5SUM =")
46:       require 'rubygems/old_format'
47: 
48:       format = Gem::OldFormat.from_file_by_path(file_path)
49:     else
50:       open file_path, Gem.binary_mode do |io|
51:         format = from_io io, file_path, security_policy
52:       end
53:     end
54: 
55:     return format
56:   end

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

[Source]

    # File lib/rubygems/format.rb, line 64
64:   def self.from_io(io, gem_path="(io)", security_policy = nil)
65:     format = new gem_path
66: 
67:     Gem::Package.open io, 'r', security_policy do |pkg|
68:       format.spec = pkg.metadata
69:       format.file_entries = []
70: 
71:       pkg.each do |entry|
72:         size = entry.header.size
73:         mode = entry.header.mode
74: 
75:         format.file_entries << [{
76:             "size" => size, "mode" => mode, "path" => entry.full_name,
77:           },
78:           entry.read
79:         ]
80:       end
81:     end
82: 
83:     format
84:   end

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

gem:[String] The file name of the gem

[Source]

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

[Validate]