Class: Reyes::TmpPersistentFile
- Inherits:
-
File
- Object
- File
- Reyes::TmpPersistentFile
- Defined in:
- lib/reyes/tmp_persistent_file.rb
Overview
Similar to Tempfile::open, but don’t unlink the file on exit.
Instance Method Summary collapse
-
#initialize(prefix = 'tmp.', tmpdir = '/tmp', suffix = '') ⇒ TmpPersistentFile
constructor
Create a temporary file of mode 0600 in the temporary directory, open it with mode “w+”, and return the open File object.
-
#make_tmpname(prefix, suffix) ⇒ Object
Generate a name for a temporary file.
Constructor Details
#initialize(prefix = 'tmp.', tmpdir = '/tmp', suffix = '') ⇒ TmpPersistentFile
Create a temporary file of mode 0600 in the temporary directory, open it with mode “w+”, and return the open File object.
6 7 8 9 |
# File 'lib/reyes/tmp_persistent_file.rb', line 6 def initialize(prefix='tmp.', tmpdir='/tmp', suffix='') path = File.join(tmpdir, make_tmpname(prefix, suffix)) super(path, File::RDWR|File::CREAT|File::EXCL, 0600) end |
Instance Method Details
#make_tmpname(prefix, suffix) ⇒ Object
Generate a name for a temporary file.
12 13 14 15 |
# File 'lib/reyes/tmp_persistent_file.rb', line 12 def make_tmpname(prefix, suffix) t = Time.now.strftime("%Y%m%d") "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}#{suffix}" end |