Class: Tempdir
- Inherits:
-
Pathname
- Object
- Pathname
- Tempdir
- Includes:
- AutoRemoval
- Defined in:
- lib/tempdir.rb
Overview
:nodoc: all
Constant Summary
Constants included from AutoRemoval
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(*args) ⇒ Tempdir
constructor
A new instance of Tempdir.
- #open(basename, *modes, &block) ⇒ Object
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
#clear ⇒ Object
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 |