Exception: Exception

Defined in:
lib/warg.rb

Instance Method Summary collapse

Instance Method Details

#full_message(highlight: true, order: :bottom) ⇒ Object



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
# File 'lib/warg.rb', line 25

def full_message(highlight: true, order: :bottom)
  trace = backtrace || [caller[0]]

  trace_head = trace[0]
  trace_tail = trace[1..-1] || []

  output = "#{trace_head}: \e[1m#{message} (\e[1;4m#{self.class}\e[m\e[1m)\e[m"

  case order.to_sym
  when :top
    unless trace_tail.empty?
      output << "\n\t from #{trace_tail.join("\n\t from ")}"
    end
  when :bottom
    trace_tail.each_with_index do |line, index|
      output.prepend "\t#{index + 1}: from #{line}\n"
    end

    output.prepend "\e[1mTraceback\e[m (most recent call last):\n"
  end

  unless highlight
    output.gsub!(/\e\[(\d+;)+m/, "")
  end

  output
end