Class: MapReduce::TempPath
- Inherits:
-
Object
- Object
- MapReduce::TempPath
- Defined in:
- lib/map_reduce/temp_path.rb
Overview
The MapReduce::TempPath generates a tempfile path and automatically deletes the file when the object is garbage collected or manually deleted. Using this class instead of Tempfile allows to have less open file descriptors.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
- .finalize(path) ⇒ Object private
Instance Method Summary collapse
-
#delete ⇒ Object
Allows to manually delete the tempfile.
-
#initialize ⇒ TempPath
constructor
Initializes a new tempfile path.
Constructor Details
#initialize ⇒ TempPath
Initializes a new tempfile path.
15 16 17 18 19 20 21 22 23 |
# File 'lib/map_reduce/temp_path.rb', line 15 def initialize @path = Dir::Tmpname.create("") do # nothing end FileUtils.touch(@path) ObjectSpace.define_finalizer(self, self.class.finalize(@path)) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/map_reduce/temp_path.rb', line 7 def path @path end |
Class Method Details
.finalize(path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 |
# File 'lib/map_reduce/temp_path.rb', line 27 def self.finalize(path) proc { FileUtils.rm_f(path) } end |
Instance Method Details
#delete ⇒ Object
Allows to manually delete the tempfile.
38 39 40 |
# File 'lib/map_reduce/temp_path.rb', line 38 def delete FileUtils.rm_f(path) end |