Class: Bookbinder::Scratch
- Inherits:
-
Object
- Object
- Bookbinder::Scratch
- Defined in:
- lib/bookbinder/scratch.rb
Overview
Manages temporary files and temporary directories, which are removed when the Ruby process exits.
Class Method Summary collapse
Class Method Details
.cleanup ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/bookbinder/scratch.rb', line 20 def self.cleanup return unless defined?(@paths) while @paths.size > 0 path = @paths.shift FileUtils.rm_r(path) if File.exists?(path) end end |
.create_tmpname(parts) ⇒ Object
29 30 31 |
# File 'lib/bookbinder/scratch.rb', line 29 def self.create_tmpname(parts) Dir::Tmpname.create(parts) { |p| raise Errno::EEXIST if File.exists?(p) } end |
.directory(path) ⇒ Object
6 7 8 9 |
# File 'lib/bookbinder/scratch.rb', line 6 def self.directory(path) @paths ||= [] create_tmpname(path).tap { |path| @paths << path } end |
.file(path) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/bookbinder/scratch.rb', line 12 def self.file(path) @paths ||= [] ext = File.extname(path) base = File.basename(path, ext) create_tmpname([base, ext]).tap { |path| @paths << path } end |