Class: Tempdir
- Includes:
- AutoRemoval
- Defined in:
- lib/rio/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.
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/rio/tempdir.rb', line 91 def initialize(*args) require 'fileutils' tmpname = createtmp(*args) do |tname| unless File.exist?(tname) FileUtils.mkpath(tname, :mode => 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
108 109 110 111 112 |
# File 'lib/rio/tempdir.rb', line 108 def clear FileUtils.rm_rf(@tmpname) @clean_proc.call ObjectSpace.undefine_finalizer(self) end |
#open(basename, *modes, &block) ⇒ Object
104 105 106 |
# File 'lib/rio/tempdir.rb', line 104 def open(basename, *modes, &block) File.open(self+basename, *modes, &block) end |