Class: BFS::TempWriter
- Inherits:
-
Tempfile
- Object
- Tempfile
- BFS::TempWriter
- Defined in:
- lib/bfs/helpers.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(name, tempdir: nil, perm: nil, **opts, &closer) ⇒ TempWriter
constructor
A new instance of TempWriter.
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
#close ⇒ Object
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 |