Class: Console::Terminal::Formatter::Failure
- Inherits:
-
Object
- Object
- Console::Terminal::Formatter::Failure
- Defined in:
- lib/console/terminal/formatter/failure.rb
Constant Summary collapse
- KEY =
:failure
Instance Method Summary collapse
- #format(event, output, prefix: nil, verbose: false, width: 80) ⇒ Object
-
#initialize(terminal) ⇒ Failure
constructor
A new instance of Failure.
Constructor Details
#initialize(terminal) ⇒ Failure
Returns a new instance of Failure.
12 13 14 15 16 17 18 19 20 |
# File 'lib/console/terminal/formatter/failure.rb', line 12 def initialize(terminal) @terminal = terminal @terminal[:exception_title] ||= @terminal.style(:red, nil, :bold) @terminal[:exception_detail] ||= @terminal.style(:yellow) @terminal[:exception_backtrace] ||= @terminal.style(:red) @terminal[:exception_backtrace_other] ||= @terminal.style(:red, nil, :faint) @terminal[:exception_message] ||= @terminal.style(:default) end |
Instance Method Details
#format(event, output, prefix: nil, verbose: false, width: 80) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/console/terminal/formatter/failure.rb', line 22 def format(event, output, prefix: nil, verbose: false, width: 80) title = event[:class] = event[:message] backtrace = event[:backtrace] root = event[:root] lines = .lines.map(&:chomp) output.puts " #{prefix}#{@terminal[:exception_title]}#{title}#{@terminal.reset}: #{lines.shift}" lines.each do |line| output.puts " #{@terminal[:exception_detail]}#{line}#{@terminal.reset}" end root_pattern = /^#{root}\// if root backtrace&.each_with_index do |line, index| path, offset, = line.split(":", 3) style = :exception_backtrace # Make the path a bit more readable: if root_pattern and path.sub!(root_pattern, "").nil? style = :exception_backtrace_other end output.puts " #{index == 0 ? "→" : " "} #{@terminal[style]}#{path}:#{offset}#{@terminal[:exception_message]} #{}#{@terminal.reset}" end if cause = event[:cause] format(cause, output, prefix: "Caused by ", verbose: verbose, width: width) end end |