Class: Tmptation::TmpDir
- Inherits:
-
Object
- Object
- Tmptation::TmpDir
- Extended by:
- Forwardable
- Includes:
- InstanceTracking, SafeDeletable
- Defined in:
- lib/tmptation.rb
Overview
Temporary directory object which behaves like core lib’s Pathname, and allows safely deleting all of its instances.
Constant Summary
Constants included from SafeDeletable
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
temporary directory’s path as a Pathname.
Class Method Summary collapse
-
.delete_all ⇒ Object
(also: -@)
Safe deletes and closes all instances.
Instance Method Summary collapse
-
#initialize(prefix = 'TmpDir-') ⇒ TmpDir
constructor
A new instance of TmpDir.
-
#method_missing(name, *args) ⇒ Object
Delegate Pathname methods to #path.
Methods included from InstanceTracking
Methods included from SafeDeletable
path_for, safe?, #safe_delete, #safe_delete_contents
Constructor Details
#initialize(prefix = 'TmpDir-') ⇒ TmpDir
Returns a new instance of TmpDir.
198 199 200 201 |
# File 'lib/tmptation.rb', line 198 def initialize(prefix='TmpDir-') super() @path = Pathname(Dir.mktmpdir(prefix)). end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
Delegate Pathname methods to #path
Allows TmpDir to behave like Pathname without having to use inheritence (which causes all sorts of issues).
210 211 212 213 214 215 216 217 |
# File 'lib/tmptation.rb', line 210 def method_missing(name, *args) #:nodoc: if path.respond_to?(name) self.class.def_delegator :@path, name #method inlining send(name, *args) else super end end |
Instance Attribute Details
#path ⇒ Object (readonly)
temporary directory’s path as a Pathname
193 194 195 |
# File 'lib/tmptation.rb', line 193 def path @path end |
Class Method Details
.delete_all ⇒ Object Also known as: -@
Safe deletes and closes all instances
182 183 184 185 |
# File 'lib/tmptation.rb', line 182 def delete_all instances.each {|instance| instance.safe_delete } instances.clear end |