Module: Report::Utils

Included in:
Csv::Table, Pdf, Xlsx
Defined in:
lib/report/utils.rb

Overview

Instance Method Summary collapse

Instance Method Details

#safe_delete(path) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/report/utils.rb', line 16

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

#tmp_path(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/report/utils.rb', line 7

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