Class Bio::Command::Tmpdir
In: lib/bio/command.rb
Parent: Object

Bio::Command::Tmpdir is a wrapper class to handle temporary directory like Tempfile class. A temporary directory is created when the object of the class is created, and automatically removed when the object is destroyed by GC.

BioRuby library internal use only.

Methods

callback   close!   new   path  

Public Class methods

Returns finalizer object for Tmpdir class. Internal use only. Users should not call this method directly.

Acknowledgement: The essense of the code is taken from tempfile.rb in Ruby 1.8.7.


Arguments:

  • (required) data: Array containing internal data
Returns:Proc object

[Source]

     # File lib/bio/command.rb, line 432
432:     def self.callback(data)
433:       pid = $$
434:       lambda {
435:         path, = *data
436:         if pid == $$
437:           $stderr.print "removing ", path, " ..." if $DEBUG
438:           if path and !path.empty? and
439:               File.directory?(path) and
440:               !File.symlink?(path) then
441:             Bio::Command.remove_entry_secure(path)
442:             $stderr.print "done\n" if $DEBUG
443:           else
444:             $stderr.print "skipped\n" if $DEBUG
445:           end
446:         end
447:       }
448:     end

Creates a new Tmpdir object. The arguments are the same as Bio::Command.mktmpdir.


Arguments:

  • (optional) prefix_suffix: String (or Array)
  • (optional) tmpdir: String: temporary directory‘s path
Returns:Tmpdir object

[Source]

     # File lib/bio/command.rb, line 458
458:     def initialize(prefix_suffix = nil, tmpdir = nil)
459:       @data = []
460:       @clean_proc = self.class.callback(@data)
461:       ObjectSpace.define_finalizer(self, @clean_proc)
462:       @data.push(@path = Bio::Command.mktmpdir(prefix_suffix, tmpdir).freeze)
463:     end

Public Instance methods

Removes the temporary directory.

Returns:nil

[Source]

     # File lib/bio/command.rb, line 475
475:     def close!
476:       # raise error if path is nil
477:       self.path
478:       # finilizer object is called to remove the directory
479:       @clean_proc.call
480:       # unregister finalizer
481:       ObjectSpace.undefine_finalizer(self)
482:       # @data and @path is removed
483:       @data = @path = nil
484:     end

Path to the temporay directory

Returns:String

[Source]

     # File lib/bio/command.rb, line 468
468:     def path
469:       @path || raise(IOError, 'removed temporary directory')
470:     end

[Validate]