Class: Kcaco::FileWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/kcaco/file_writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception) ⇒ FileWriter

Returns a new instance of FileWriter.



11
12
13
# File 'lib/kcaco/file_writer.rb', line 11

def initialize(exception)
  self.exception = exception
end

Instance Attribute Details

#exceptionObject

Returns the value of attribute exception.



9
10
11
# File 'lib/kcaco/file_writer.rb', line 9

def exception
  @exception
end

Instance Method Details

#save(path) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kcaco/file_writer.rb', line 16

def save(path)
  FileUtils.mkdir_p(File.dirname(path))
  File.open(path, "w") do |f|
    [
     ["time", Time.now.iso8601],
     ["type", exception.type],
     ["message", exception.message],
     ["payload", exception.payload],
    ].each do |label, text|
      f.puts([label, text].join(": "))
    end

    f.puts("backtrace:")
    exception.backtrace.each do |line|
      f.puts(line)
    end

    f.puts
    f.puts(exception.to_yaml)
  end
end