Module: Omnizip::Temp
- Defined in:
- lib/omnizip/temp.rb,
lib/omnizip/temp/temp_file.rb,
lib/omnizip/temp/safe_extract.rb,
lib/omnizip/temp/temp_file_pool.rb
Overview
Temporary file management with automatic cleanup Provides safe, atomic operations with RAII pattern
Defined Under Namespace
Classes: ArchiveHelper, Configuration, SafeExtract, TempFile, TempFilePool, TempFileRegistry
Class Method Summary collapse
-
.cleanup_all ⇒ Object
Cleanup all tracked temp files.
-
.configuration ⇒ Configuration
Global configuration.
-
.configure {|config| ... } ⇒ Object
Configure temp file operations.
-
.directory(prefix: nil) {|path| ... } ⇒ Object
Create temporary directory with automatic cleanup.
-
.file(prefix: nil, suffix: "") {|path| ... } ⇒ Object
Create temporary file with automatic cleanup.
-
.registry ⇒ TempFileRegistry
Get temp file registry.
-
.with_archive(format: :zip) {|archive| ... } ⇒ Object
Create temporary archive with automatic cleanup.
Class Method Details
.cleanup_all ⇒ Object
Cleanup all tracked temp files
91 92 93 |
# File 'lib/omnizip/temp.rb', line 91 def cleanup_all registry.cleanup_all end |
.configuration ⇒ Configuration
Global configuration
26 27 28 |
# File 'lib/omnizip/temp.rb', line 26 def configuration @configuration ||= Configuration.new end |
.configure {|config| ... } ⇒ Object
Configure temp file operations
32 33 34 35 |
# File 'lib/omnizip/temp.rb', line 32 def configure yield configuration setup_cleanup_hooks if configuration.cleanup_on_exit end |
.directory(prefix: nil) {|path| ... } ⇒ Object
Create temporary directory with automatic cleanup
64 65 66 67 68 69 |
# File 'lib/omnizip/temp.rb', line 64 def directory(prefix: nil, &block) require "tmpdir" prefix ||= configuration.prefix Dir.mktmpdir(prefix, configuration.directory, &block) end |
.file(prefix: nil, suffix: "") {|path| ... } ⇒ Object
Create temporary file with automatic cleanup
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/omnizip/temp.rb', line 42 def file(prefix: nil, suffix: "") prefix ||= configuration.prefix temp_file = TempFile.new( prefix: prefix, suffix: suffix, directory: configuration.directory, ) registry.track(temp_file) begin yield(temp_file.path) ensure registry.untrack(temp_file) temp_file.unlink unless temp_file.kept? end end |
.registry ⇒ TempFileRegistry
Get temp file registry
86 87 88 |
# File 'lib/omnizip/temp.rb', line 86 def registry @registry ||= TempFileRegistry.new end |
.with_archive(format: :zip) {|archive| ... } ⇒ Object
Create temporary archive with automatic cleanup
75 76 77 78 79 80 81 82 |
# File 'lib/omnizip/temp.rb', line 75 def with_archive(format: :zip) suffix = format == :zip ? ".zip" : ".7z" file(suffix: suffix) do |path| archive = ArchiveHelper.new(path, format) yield(archive) end end |