Class: IO::Memory::Generic::Implementation::Handle

Inherits:
Object
  • Object
show all
Defined in:
lib/io/memory/generic.rb

Overview

Handle class that wraps the IO and manages tempfile cleanup

Instance Method Summary collapse

Constructor Details

#initialize(io, tempfile, size) ⇒ Handle

Returns a new instance of Handle.



20
21
22
23
24
# File 'lib/io/memory/generic.rb', line 20

def initialize(io, tempfile, size)
  @io = io
  @tempfile = tempfile
  @size = size
end

Instance Method Details

#closeObject



35
36
37
38
39
40
41
42
43
# File 'lib/io/memory/generic.rb', line 35

def close
  @io.close unless @io.closed?
ensure
  # Clean up tempfile
  if @tempfile && !@tempfile.closed?
    @tempfile.close
    @tempfile = nil
  end
end

#closed?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/io/memory/generic.rb', line 45

def closed?
  @io.closed?
end

#ioObject



26
27
28
# File 'lib/io/memory/generic.rb', line 26

def io
  @io
end

#map(size = nil) ⇒ Object



30
31
32
33
# File 'lib/io/memory/generic.rb', line 30

def map(size = nil)
  size ||= @size
  ::IO::Buffer.map(@io, size)
end