Class: Tempdir

Inherits:
Pathname
  • Object
show all
Includes:
AutoRemoval
Defined in:
lib/tempdir.rb

Overview

:nodoc: all

Constant Summary

Constants included from AutoRemoval

AutoRemoval::MAX_TRY

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Tempdir

Returns a new instance of Tempdir.



102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/tempdir.rb', line 102

def initialize(*args)
require 'fileutils'

tmpname = createtmp(*args) do |tmpname|
  unless File.exist?(tmpname)
    Dir.mkdir(tmpname, 0700)
  end
end

super(tmpname)
@clean_proc, = AutoRemoval.callback(tmpname, FileUtils.method(:rm_rf))
ObjectSpace.define_finalizer(self, @clean_proc)  end

Instance Method Details

#clearObject



119
120
121
122
123
# File 'lib/tempdir.rb', line 119

def clear
  FileUtils.rm_rf(@tmpname)
  @clean_proc.call
  ObjectSpace.undefine_finalizer(self)
end

#open(basename, *modes, &block) ⇒ Object



115
116
117
# File 'lib/tempdir.rb', line 115

def open(basename, *modes, &block)
  File.open(self+basename, *modes, &block)
end