Class: Gem::Package::IOSource

Inherits:
Source show all
Defined in:
lib/rubygems/package/io_source.rb

Overview

Supports reading and writing gems from/to a generic IO object. This is useful for other applications built on top of rubygems, such as rubygems.org.

This is a private class, do not depend on it directly. Instead, pass an IO object to ‘Gem::Package.new`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ IOSource

Returns a new instance of IOSource.



13
14
15
# File 'lib/rubygems/package/io_source.rb', line 13

def initialize(io)
  @io = io
end

Instance Attribute Details

#ioObject (readonly)

:nodoc: all



11
12
13
# File 'lib/rubygems/package/io_source.rb', line 11

def io
  @io
end

Instance Method Details

#pathObject



41
42
# File 'lib/rubygems/package/io_source.rb', line 41

def path
end

#present?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/rubygems/package/io_source.rb', line 29

def present?
  true
end

#startObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rubygems/package/io_source.rb', line 17

def start
  @start ||= begin
    if io.pos > 0
      raise Gem::Package::Error, "Cannot read start unless IO is at start"
    end

    value = io.read 20
    io.rewind
    value
  end
end

#with_read_io {|io| ... } ⇒ Object

Yields:



33
34
35
# File 'lib/rubygems/package/io_source.rb', line 33

def with_read_io
  yield io
end

#with_write_io {|io| ... } ⇒ Object

Yields:



37
38
39
# File 'lib/rubygems/package/io_source.rb', line 37

def with_write_io
  yield io
end