class TraceTree::TmpFile
Constants
- DefaultName
Public Class Methods
new(path, transcode: false)
click to toggle source
# File lib/trace_tree/tmp_file.rb, line 15 def initialize path, transcode: false path = recognize_dir path @tmp = custom path @transcode = transcode end
Public Instance Methods
path()
click to toggle source
# File lib/trace_tree/tmp_file.rb, line 29 def path @tmp end
puts(*content)
click to toggle source
# File lib/trace_tree/tmp_file.rb, line 21 def puts *content content = content.map{ |c| c.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?') } if @transcode File.open @tmp, 'a' do |f| f.puts(*content) end end
Private Instance Methods
custom(path)
click to toggle source
# File lib/trace_tree/tmp_file.rb, line 46 def custom path path = Array(path).map(&:to_s) path[-1] = time + path[-1] path = [Dir.tmpdir] + path ensure_parent path File.join(*path) end
ensure_parent(path_arr)
click to toggle source
# File lib/trace_tree/tmp_file.rb, line 58 def ensure_parent path_arr dir = path_arr[0..-2] FileUtils.mkdir_p File.join(*dir) end
recognize_dir(path)
click to toggle source
# File lib/trace_tree/tmp_file.rb, line 35 def recognize_dir path case path when true DefaultName when String path.split '/' else path end end
time()
click to toggle source
# File lib/trace_tree/tmp_file.rb, line 54 def time Time.now.strftime '%Y%m%d_%H%M%S_%L_' end