Class: Tempfile::Remover

Inherits:
Object
  • Object
show all
Defined in:
lib/rubysl/tempfile/tempfile.rb

Overview

:stopdoc:

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Remover

Returns a new instance of Remover.



268
269
270
271
# File 'lib/rubysl/tempfile/tempfile.rb', line 268

def initialize(data)
  @pid = $$
  @data = data
end

Instance Method Details

#call(*args) ⇒ Object



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/rubysl/tempfile/tempfile.rb', line 273

def call(*args)
  if @pid == $$
    path, tmpfile = *@data

    STDERR.print "removing ", path, "..." if $DEBUG

    tmpfile.close if tmpfile

    # keep this order for thread safeness
    if path
      File.unlink(path) if File.exist?(path)
    end

    STDERR.print "done\n" if $DEBUG
  end
end