Module: DRbQS::Temporary
- Defined in:
- lib/drbqs/utility/temporary.rb
Class Method Summary collapse
-
.delete ⇒ Object
Delete all temporary directory.
-
.directory ⇒ Object
Create new temporary directory and return the path of directory.
-
.file(basename = nil) ⇒ Object
Return new path of temporary file.
-
.filename ⇒ Object
Return FileName object to generate names of temporary files on DRbQS nodes.
-
.root ⇒ Object
Return root of temporary directory.
- .set_sub_directory(dir) ⇒ Object
- .socket_path ⇒ Object
- .subdirectory ⇒ Object
Class Method Details
.delete ⇒ Object
Delete all temporary directory.
57 58 59 60 61 62 63 64 |
# File 'lib/drbqs/utility/temporary.rb', line 57 def self.delete if @root FileUtils.rm_r(@root) @pid = nil @root = nil @filename = nil end end |
.directory ⇒ Object
Create new temporary directory and return the path of directory.
42 43 44 |
# File 'lib/drbqs/utility/temporary.rb', line 42 def self.directory filename.create(:add => :always, :directory => :self) end |
.file(basename = nil) ⇒ Object
Return new path of temporary file.
48 49 50 51 52 53 54 |
# File 'lib/drbqs/utility/temporary.rb', line 48 def self.file(basename = nil) if basename File.join(self.directory, basename) else filename.create(:add => :always, :directory => :parent) end end |
.filename ⇒ Object
Return FileName object to generate names of temporary files on DRbQS nodes.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/drbqs/utility/temporary.rb', line 30 def self.filename unless @filename if @subdir @filename = FileName.new(File.join(@subdir, sprintf("temp_%d", rand(10000)))) else @filename = FileName.new(File.join(self.root, sprintf("temp_%d", rand(10000)))) end end @filename end |
.root ⇒ Object
Return root of temporary directory.
11 12 13 14 15 16 17 18 |
# File 'lib/drbqs/utility/temporary.rb', line 11 def self.root if @pid != Process.pid @pid = Process.pid @root = File.join(Dir.tmpdir, sprintf("drbqs_%s_%d_%d", ENV['USER'], @pid, rand(10000))) FileUtils.mkdir_p(@root, :mode => 0700) end @root end |
.set_sub_directory(dir) ⇒ Object
20 21 22 23 |
# File 'lib/drbqs/utility/temporary.rb', line 20 def self.set_sub_directory(dir) @filename = nil @subdir = File.join(self.root, dir) end |
.socket_path ⇒ Object
66 67 68 |
# File 'lib/drbqs/utility/temporary.rb', line 66 def self.socket_path FileName.create(self.root, "socket", :add => :always, :type => :time) end |
.subdirectory ⇒ Object
25 26 27 |
# File 'lib/drbqs/utility/temporary.rb', line 25 def self.subdirectory @subdir && File.exist?(@subdir) ? @subdir : nil end |