Class: IO::Memory::Generic::Implementation::Handle
- Inherits:
-
Object
- Object
- IO::Memory::Generic::Implementation::Handle
- Defined in:
- lib/io/memory/generic.rb
Overview
Handle class that wraps the IO and manages tempfile cleanup
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(io, tempfile, size) ⇒ Handle
constructor
A new instance of Handle.
- #io ⇒ Object
- #map(size = nil) ⇒ Object
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
#close ⇒ Object
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
45 46 47 |
# File 'lib/io/memory/generic.rb', line 45 def closed? @io.closed? end |
#io ⇒ Object
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 |