Class: LibGems::Format
- Inherits:
-
Object
- Object
- LibGems::Format
- Extended by:
- UserInteraction
- Defined in:
- lib/libgems/format.rb
Overview
LibGems::Format knows the guts of the RubyGem .gem file format and provides the capability to read gem files
Instance Attribute Summary collapse
-
#file_entries ⇒ Object
Returns the value of attribute file_entries.
-
#gem_path ⇒ Object
Returns the value of attribute gem_path.
-
#spec ⇒ Object
Returns the value of attribute spec.
Class Method Summary collapse
-
.from_file_by_path(file_path, security_policy = nil) ⇒ Object
Reads the gem
file_path
usingsecurity_policy
and returns a Format representing the data in the gem. -
.from_io(io, gem_path = "(io)", security_policy = nil) ⇒ Object
Reads a gem from
io
atgem_path
usingsecurity_policy
and returns a Format representing the data from the gem.
Instance Method Summary collapse
-
#initialize(gem_path) ⇒ Format
constructor
Constructs a Format representing the gem’s data which came from
gem_path
.
Methods included from UserInteraction
Methods included from DefaultUserInteraction
ui, #ui, ui=, #ui=, use_ui, #use_ui
Constructor Details
#initialize(gem_path) ⇒ Format
Constructs a Format representing the gem’s data which came from gem_path
26 27 28 |
# File 'lib/libgems/format.rb', line 26 def initialize(gem_path) @gem_path = gem_path end |
Instance Attribute Details
#file_entries ⇒ Object
Returns the value of attribute file_entries.
18 19 20 |
# File 'lib/libgems/format.rb', line 18 def file_entries @file_entries end |
#gem_path ⇒ Object
Returns the value of attribute gem_path.
19 20 21 |
# File 'lib/libgems/format.rb', line 19 def gem_path @gem_path end |
#spec ⇒ Object
Returns the value of attribute spec.
17 18 19 |
# File 'lib/libgems/format.rb', line 17 def spec @spec end |
Class Method Details
.from_file_by_path(file_path, security_policy = nil) ⇒ Object
Reads the gem file_path
using security_policy
and returns a Format representing the data in the gem
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/libgems/format.rb', line 34 def self.from_file_by_path(file_path, security_policy = nil) unless File.exist?(file_path) raise LibGems::Exception, "Cannot load gem at [#{file_path}] in #{Dir.pwd}" end start = File.read file_path, 20 if start.nil? or start.length < 20 then nil elsif start.include?("MD5SUM =") # old version gems require 'libgems/old_format' LibGems::OldFormat.from_file_by_path file_path else open file_path, LibGems.binary_mode do |io| from_io io, file_path, security_policy end end end |
.from_io(io, gem_path = "(io)", security_policy = nil) ⇒ Object
Reads a gem from io
at gem_path
using security_policy
and returns a Format representing the data from the gem
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/libgems/format.rb', line 58 def self.from_io(io, gem_path="(io)", security_policy = nil) format = new gem_path LibGems::Package.open io, 'r', security_policy do |pkg| format.spec = pkg. format.file_entries = [] pkg.each do |entry| size = entry.header.size mode = entry.header.mode format.file_entries << [{ "size" => size, "mode" => mode, "path" => entry.full_name, }, entry.read ] end end format end |