Class: StructuredWarnings::Warner

Inherits:
Object
  • Object
show all
Defined in:
lib/structured_warnings/warner.rb

Overview

The Warner class implements a very simple interface. It simply formats a warning, so it is more than just the message itself. This default warner uses a format comparable to warnings emitted by rb_warn including the place where the “thing that caused the warning” resides.

Direct Known Subclasses

Test::Warner

Instance Method Summary collapse

Instance Method Details

#format(warning, message, options, stack) ⇒ Object

Warner.new.format(StructuredWarning::DeprecationWarning, “more info..”, caller)

# => "demo.rb:5 : more info.. (StructuredWarning::DeprecationWarning)"


8
9
10
11
12
13
14
15
16
17
18
# File 'lib/structured_warnings/warner.rb', line 8

def format(warning, message, options, stack)
  frame = stack.shift
  # This file contains the backwards compatibility code for Ruby 2.3 and
  # lower, let's skip it
  frame = stack.shift if frame.include? 'lib/structured_warnings/kernel.rb'

  # Handle introduced uplevel introduced in Ruby 2.5
  frame = stack.shift(options[:uplevel]).last if options[:uplevel]

  "#{frame}: #{message} (#{warning})\n"
end