Class: Bio::Command::Tmpdir

Inherits:
Object show all
Defined in:
lib/bio/command.rb

Overview

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.

Defined Under Namespace

Classes: Remover

Instance Method Summary collapse

Constructor Details

#initialize(prefix_suffix = nil, tmpdir = nil) ⇒ Tmpdir

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


667
668
669
670
671
672
# File 'lib/bio/command.rb', line 667

def initialize(prefix_suffix = nil, tmpdir = nil)
  @data = []
  @clean_proc = Remover.new(@data)
  ObjectSpace.define_finalizer(self, @clean_proc)
  @data.push(@path = Bio::Command.mktmpdir(prefix_suffix, tmpdir).freeze)
end

Instance Method Details

#close!Object

Removes the temporary directory.

Returns

nil


684
685
686
687
688
689
690
691
692
693
# File 'lib/bio/command.rb', line 684

def close!
  # raise error if path is nil
  self.path
  # finilizer object is called to remove the directory
  @clean_proc.call
  # unregister finalizer
  ObjectSpace.undefine_finalizer(self)
  # @data and @path is removed
  @data = @path = nil
end

#pathObject

Path to the temporay directory

Returns

String


677
678
679
# File 'lib/bio/command.rb', line 677

def path
  @path || raise(IOError, 'removed temporary directory')
end