class Siba::TmpDir

Constants

TmpDirPrefix

Public Class Methods

new() click to toggle source
# File lib/siba/tmp_dir.rb, line 9
def initialize
  @tmp_dir = nil
end
test_access() click to toggle source
# File lib/siba/tmp_dir.rb, line 25
      def test_access
        siba_file.run_this "test access" do
          begin
            tmp_dir_obj = TmpDir.new
            test_dir = tmp_dir_obj.get
            raise unless siba_file.file_directory? test_dir
            tmp_dir_obj.cleanup
          rescue Exception
            logger.error %q{Can not create temporary directory.
Please make sure you have write permissions to the system temporary folder.
You can also specify the alternative location for temporary folder in options:

settings:
  tmp_dir: ~/your_tmp_dir
}
            raise
          end
          logger.debug "Access to temporary directory verified"
        end
      end

Public Instance Methods

cleanup() click to toggle source
# File lib/siba/tmp_dir.rb, line 17
def cleanup
  siba_file.file_utils_remove_entry_secure @tmp_dir unless @tmp_dir.nil?
  @tmp_dir = nil
end
get() click to toggle source
# File lib/siba/tmp_dir.rb, line 13
def get
  @tmp_dir ||= create
end

Protected Instance Methods

create() click to toggle source
# File lib/siba/tmp_dir.rb, line 49
def create
  siba_file.run_this "create tmp dir" do
    tmp_dir_from_settings = Siba.settings && Siba.settings["tmp_dir"]
    tmp_path = nil
    if tmp_dir_from_settings.nil?
      tmp_path = siba_file.dir_mktmpdir TmpDirPrefix
    else
      tmp_path = File.join(siba_file.file_expand_path(tmp_dir_from_settings),
                              "#{TmpDirPrefix}#{Siba::TestFiles.random_suffix}")
      siba_file.file_utils_mkpath tmp_path
    end
    tmp_path
  end
end