Class: BFS::TempWriter

Inherits:
Tempfile
  • Object
show all
Defined in:
lib/bfs/helpers.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, opts = {}, &closer) ⇒ TempWriter

Returns a new instance of TempWriter.



6
7
8
9
10
# File 'lib/bfs/helpers.rb', line 6

def initialize(name, opts={}, &closer)
  @closer   = closer
  @tempfile = ::Tempfile.new(File.basename(name.to_s), opts)
  super @tempfile
end

Instance Method Details

#closeObject



12
13
14
15
16
17
18
19
# File 'lib/bfs/helpers.rb', line 12

def close
  return if closed?

  path = @tempfile.path
  @tempfile.close
  @closer&.call(path)
  @tempfile.unlink
end