Class: Omnizip::Temp::TempFileRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/temp.rb

Overview

Registry to track all temp files

Instance Method Summary collapse

Constructor Details

#initializeTempFileRegistry

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_allObject

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

#countInteger

Get count of tracked files

Returns:

  • (Integer)

    Number 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

Parameters:

  • temp_file (TempFile)

    File to track



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

Parameters:

  • temp_file (TempFile)

    File to untrack



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