Sha256: a761677f65472cbc615bf4b2506b63b464fa8c1d831d45e5b297dab85df5b0dc

Contents?: true

Size: 907 Bytes

Versions: 1

Compression:

Stored size: 907 Bytes

Contents

# 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.
class StructuredWarnings::Warner
  #  Warner.new.format(StructuredWarning::DeprecationWarning, "more info..", caller)
  #     # => "demo.rb:5 : more info.. (StructuredWarning::DeprecationWarning)"
  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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
structured_warnings-0.4.0 lib/structured_warnings/warner.rb