123456789_123456789_123456789_123456789_123456789_

Class: Tempfile::FinalizerManager

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/tempfile.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(path) ⇒ FinalizerManager

[ GitHub ]

  
# File 'lib/tempfile.rb', line 373

def initialize(path)
  @open_files = {}
  @path = path
  @pid = Process.pid
  @unlinked = false
end

Instance Attribute Details

#unlinked (rw)

[ GitHub ]

  
# File 'lib/tempfile.rb', line 371

attr_accessor :unlinked

Instance Method Details

#call(object_id)

[ GitHub ]

  
# 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)

[ GitHub ]

  
# 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