Sha256: dd061c52ee5c90713ad45949394189fdcaa4120f60228dd1992bb029f29d4c9b

Contents?: true

Size: 1.31 KB

Versions: 54

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

# `uplevel` keyword argument of Kernel#warn is available since ruby 2.5.
if RUBY_VERSION >= "2.5" && !Gem::KERNEL_WARN_IGNORES_INTERNAL_ENTRIES

  module Kernel
    rubygems_path = "#{__dir__}/" # Frames to be skipped start with this path.

    original_warn = instance_method(:warn)

    remove_method :warn

    class << self
      remove_method :warn
    end

    module_function define_method(:warn) {|*messages, **kw|
      unless uplevel = kw[:uplevel]
        if Gem.java_platform?
          return original_warn.bind(self).call(*messages)
        else
          return original_warn.bind(self).call(*messages, **kw)
        end
      end

      # Ensure `uplevel` fits a `long`
      uplevel, = [uplevel].pack("l!").unpack("l!")

      if uplevel >= 0
        start = 0
        while uplevel >= 0
          loc, = caller_locations(start, 1)
          unless loc
            # No more backtrace
            start += uplevel
            break
          end

          start += 1

          if path = loc.path
            unless path.start_with?(rubygems_path) or path.start_with?('<internal:')
              # Non-rubygems frames
              uplevel -= 1
            end
          end
        end
        kw[:uplevel] = start
      end

      original_warn.bind(self).call(*messages, **kw)
    }
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
rubygems-update-3.2.34 lib/rubygems/core_ext/kernel_warn.rb
rubygems-update-3.3.18 lib/rubygems/core_ext/kernel_warn.rb
rubygems-update-3.3.17 lib/rubygems/core_ext/kernel_warn.rb
rubygems-update-3.3.16 lib/rubygems/core_ext/kernel_warn.rb
rubygems-update-3.3.15 lib/rubygems/core_ext/kernel_warn.rb
rubygems-update-3.3.14 lib/rubygems/core_ext/kernel_warn.rb
rubygems-update-3.3.13 lib/rubygems/core_ext/kernel_warn.rb
rubygems-update-3.3.12 lib/rubygems/core_ext/kernel_warn.rb
rubygems-update-3.3.11 lib/rubygems/core_ext/kernel_warn.rb
rubygems-update-3.3.10 lib/rubygems/core_ext/kernel_warn.rb
rubygems-update-3.3.9 lib/rubygems/core_ext/kernel_warn.rb
rubygems-update-3.3.8 lib/rubygems/core_ext/kernel_warn.rb
rubygems-update-3.3.7 lib/rubygems/core_ext/kernel_warn.rb
rubygems-update-3.3.6 lib/rubygems/core_ext/kernel_warn.rb
rubygems-update-3.3.5 lib/rubygems/core_ext/kernel_warn.rb
rubygems-update-3.3.4 lib/rubygems/core_ext/kernel_warn.rb
rubygems-update-3.3.3 lib/rubygems/core_ext/kernel_warn.rb
rubygems-update-3.3.2 lib/rubygems/core_ext/kernel_warn.rb
rubygems-update-3.3.1 lib/rubygems/core_ext/kernel_warn.rb
rubygems-update-3.3.0 lib/rubygems/core_ext/kernel_warn.rb