Sha256: 405388a58ba906f8e3a78c4e752e15c4c3c9976d4c40f585ac6580c34979ba1e

Contents?: true

Size: 757 Bytes

Versions: 3

Compression:

Stored size: 757 Bytes

Contents

require 'tmpdir'
require 'fileutils'

class Report
  # stolen from https://github.com/seamusabshere/unix_utils
  module Utils
    def tmp_path(options = {})
      ancestor = [ self.class.name, options[:hint] ].compact.join('_')
      extname = options.fetch(:extname, '.tmp')
      basename = File.basename ancestor.sub(/^\d{9,}_/, '')
      basename.gsub! /\W/, '_'
      time = Time.now.strftime('%H%M%S%L')
      File.join Dir.tmpdir, [time, '_', basename[0..(234-extname.length)], extname].join
    end

    def safe_delete(path)
      path = File.expand_path path
      unless File.dirname(path).start_with?(Dir.tmpdir)
        raise "Refusing to rm -rf #{path} because it's not in #{Dir.tmpdir}"
      end
      FileUtils.rm_rf path
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
report-0.1.1 lib/report/utils.rb
report-0.1.0 lib/report/utils.rb
report-0.0.3 lib/report/utils.rb