Module: Report::Utils
- Included in:
- Csv::Table, Pdf, Xlsx
- Defined in:
- lib/report/utils.rb
Overview
stolen from github.com/seamusabshere/unix_utils
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. 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( = {}) ancestor = [ self.class.name, [:hint] ].compact.join('_') extname = .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 |