Class: BFS::TempWriter

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

Instance Method Summary collapse

Constructor Details

#initialize(name, tempdir: nil, perm: nil, **opts, &closer) ⇒ TempWriter

Returns a new instance of TempWriter.



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

def initialize(name, tempdir: nil, perm: nil, **opts, &closer)
  @closer   = closer
  @tempfile = ::Tempfile.new(File.basename(name.to_s), tempdir, **opts)
  @tempfile.chmod(perm) if perm
  super @tempfile
end

Instance Method Details

#closeObject



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

def close
  return if closed?

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