Class: Gem::Package::IOSource

Inherits:
Source
  • Object
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.



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

def initialize(io)
  @io = io
end

Instance Attribute Details

#ioObject (readonly)

:nodoc: all



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

def io
  @io
end

Instance Method Details

#pathObject



46
47
# File 'lib/rubygems/package/io_source.rb', line 46

def path
end

#present?Boolean

Returns:

  • (Boolean)


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

def present?
  true
end

#startObject



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

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_ioObject



34
35
36
37
38
# File 'lib/rubygems/package/io_source.rb', line 34

def with_read_io
  yield io
ensure
  io.rewind
end

#with_write_ioObject



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

def with_write_io
  yield io
ensure
  io.rewind
end