Class: Tempfile::FinalizerManager
- Inherits:
-
Object
- Object
- Tempfile::FinalizerManager
- Defined in:
- lib/tempfile.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#unlinked ⇒ Object
Returns the value of attribute unlinked.
Instance Method Summary collapse
- #call(object_id) ⇒ Object
-
#initialize(path) ⇒ FinalizerManager
constructor
A new instance of FinalizerManager.
- #register(obj, file) ⇒ Object
Constructor Details
#initialize(path) ⇒ FinalizerManager
Returns a new instance of FinalizerManager.
373 374 375 376 377 378 |
# File 'lib/tempfile.rb', line 373 def initialize(path) @open_files = {} @path = path @pid = Process.pid @unlinked = false end |
Instance Attribute Details
#unlinked ⇒ Object
Returns the value of attribute unlinked.
371 372 373 |
# File 'lib/tempfile.rb', line 371 def unlinked @unlinked end |
Instance Method Details
#call(object_id) ⇒ Object
386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'lib/tempfile.rb', line 386 def call(object_id) @open_files.delete(object_id).close if @open_files.empty? && !@unlinked && Process.pid == @pid $stderr.puts "removing #{@path}..." if $DEBUG begin File.unlink(@path) rescue Errno::ENOENT end $stderr.puts "done" if $DEBUG end end |
#register(obj, file) ⇒ Object
380 381 382 383 384 |
# File 'lib/tempfile.rb', line 380 def register(obj, file) ObjectSpace.undefine_finalizer(obj) ObjectSpace.define_finalizer(obj, self) @open_files[obj.object_id] = file end |