Class: CdoTempfileStore
- Inherits:
-
Object
- Object
- CdoTempfileStore
- Defined in:
- lib/cdo.rb
Overview
Helper module for easy temp file handling {{{
Constant Summary collapse
- N =
base for persitent temp files - just for debugging
10000000
Instance Method Summary collapse
- #cleanTempDir ⇒ Object
-
#initialize(dir = Dir.tmpdir) ⇒ CdoTempfileStore
constructor
A new instance of CdoTempfileStore.
- #newFile ⇒ Object
- #setPersist(value) ⇒ Object
- #showFiles ⇒ Object
Constructor Details
#initialize(dir = Dir.tmpdir) ⇒ CdoTempfileStore
Returns a new instance of CdoTempfileStore.
495 496 497 498 499 500 501 502 503 504 505 |
# File 'lib/cdo.rb', line 495 def initialize(dir=Dir.tmpdir) @dir = dir @tag = 'Cdorb' @persistent_tempfiles = false # storage for filenames in order to prevent too early removement @_tempfiles = [] # make sure the tempdir ie really there Dir.mkdir(@dir) unless Dir.exists?(@dir) end |
Instance Method Details
#cleanTempDir ⇒ Object
528 529 530 531 532 533 |
# File 'lib/cdo.rb', line 528 def cleanTempDir # filter by name, realfile and ownership Dir.entries(@dir).map {|f| "#@dir/#{f}"}.find_all {|file| File.file?(file) and File.owned?(file) and file.include?(@tag) }.each {|f| File.unlink(f)} end |
#newFile ⇒ Object
511 512 513 514 515 516 517 518 519 520 521 522 |
# File 'lib/cdo.rb', line 511 def newFile unless @persistent_tempfiles t = Tempfile.new(@tag,@dir) @_tempfiles << t @_tempfiles << t.path t.path else t = "_"+rand(N).to_s @_tempfiles << t t end end |
#setPersist(value) ⇒ Object
507 508 509 |
# File 'lib/cdo.rb', line 507 def setPersist(value) @persistent_tempfiles = value end |
#showFiles ⇒ Object
524 525 526 |
# File 'lib/cdo.rb', line 524 def showFiles @_tempfiles.each {|f| print(f+" ") if f.kind_of? String} end |