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.
486 487 488 489 490 491 492 493 494 495 496 |
# File 'lib/cdo.rb', line 486 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
519 520 521 522 523 524 |
# File 'lib/cdo.rb', line 519 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
502 503 504 505 506 507 508 509 510 511 512 513 |
# File 'lib/cdo.rb', line 502 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
498 499 500 |
# File 'lib/cdo.rb', line 498 def setPersist(value) @persistent_tempfiles = value end |
#showFiles ⇒ Object
515 516 517 |
# File 'lib/cdo.rb', line 515 def showFiles @_tempfiles.each {|f| print(f+" ") if f.kind_of? String} end |