class Bio::Command::Tmpdir

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.

Public Class Methods

new(prefix_suffix = nil, tmpdir = nil) click to toggle source

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

# File lib/bio/command.rb, line 668
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

Public Instance Methods

close!() click to toggle source

Removes the temporary directory.

Returns

nil

# File lib/bio/command.rb, line 685
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
path() click to toggle source

Path to the temporay directory

Returns

String

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