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.
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:
Returns: | Proc object |
# File lib/bio/command.rb, line 560 560: def self.callback(data) 561: pid = $$ 562: lambda { 563: path, = *data 564: if pid == $$ 565: $stderr.print "removing ", path, " ..." if $DEBUG 566: if path and !path.empty? and 567: File.directory?(path) and 568: !File.symlink?(path) then 569: Bio::Command.remove_entry_secure(path) 570: $stderr.print "done\n" if $DEBUG 571: else 572: $stderr.print "skipped\n" if $DEBUG 573: end 574: end 575: } 576: end
Creates a new Tmpdir object. The arguments are the same as Bio::Command.mktmpdir.
Arguments:
Returns: | Tmpdir object |
# File lib/bio/command.rb, line 586 586: def initialize(prefix_suffix = nil, tmpdir = nil) 587: @data = [] 588: @clean_proc = self.class.callback(@data) 589: ObjectSpace.define_finalizer(self, @clean_proc) 590: @data.push(@path = Bio::Command.mktmpdir(prefix_suffix, tmpdir).freeze) 591: end
Removes the temporary directory.
Returns: | nil |
# File lib/bio/command.rb, line 603 603: def close! 604: # raise error if path is nil 605: self.path 606: # finilizer object is called to remove the directory 607: @clean_proc.call 608: # unregister finalizer 609: ObjectSpace.undefine_finalizer(self) 610: # @data and @path is removed 611: @data = @path = nil 612: end