Class: Omnizip::Temp::TempFileRegistry
- Inherits:
-
Object
- Object
- Omnizip::Temp::TempFileRegistry
- Defined in:
- lib/omnizip/temp.rb
Overview
Registry to track all temp files
Instance Method Summary collapse
-
#cleanup_all ⇒ Object
Cleanup all tracked files.
-
#count ⇒ Integer
Get count of tracked files.
-
#initialize ⇒ TempFileRegistry
constructor
A new instance of TempFileRegistry.
-
#track(temp_file) ⇒ Object
Track a temp file.
-
#untrack(temp_file) ⇒ Object
Untrack a temp file.
Constructor Details
#initialize ⇒ TempFileRegistry
Returns a new instance of TempFileRegistry.
141 142 143 144 |
# File 'lib/omnizip/temp.rb', line 141 def initialize @temp_files = [] @mutex = Mutex.new end |
Instance Method Details
#cleanup_all ⇒ Object
Cleanup all tracked files
163 164 165 166 167 168 169 170 171 172 |
# File 'lib/omnizip/temp.rb', line 163 def cleanup_all @mutex.synchronize do @temp_files.each do |temp_file| temp_file.unlink rescue StandardError nil end @temp_files.clear end end |
#count ⇒ Integer
Get count of tracked files
176 177 178 |
# File 'lib/omnizip/temp.rb', line 176 def count @mutex.synchronize { @temp_files.size } end |
#track(temp_file) ⇒ Object
Track a temp file
148 149 150 151 152 |
# File 'lib/omnizip/temp.rb', line 148 def track(temp_file) @mutex.synchronize do @temp_files << temp_file end end |
#untrack(temp_file) ⇒ Object
Untrack a temp file
156 157 158 159 160 |
# File 'lib/omnizip/temp.rb', line 156 def untrack(temp_file) @mutex.synchronize do @temp_files.delete(temp_file) end end |