2018-09-23 23:14:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
if RUBY_VERSION >= "2.5"
|
|
|
|
module Kernel
|
|
|
|
path = "#{__dir__}/"
|
|
|
|
original_warn = instance_method(:warn)
|
|
|
|
Module.new {define_method(:warn, original_warn)}
|
|
|
|
original_warn = method(:warn)
|
|
|
|
|
2018-09-24 09:04:40 -04:00
|
|
|
module_function define_method(:warn) {|*messages, uplevel: nil|
|
2018-09-23 23:14:43 -04:00
|
|
|
if uplevel
|
2018-09-24 10:26:00 -04:00
|
|
|
uplevel, = [uplevel].pack("l!").unpack("l!")
|
|
|
|
if uplevel >= 0
|
|
|
|
start = 0
|
|
|
|
begin
|
|
|
|
loc, = caller_locations(start, 1)
|
|
|
|
break start += uplevel unless loc
|
|
|
|
start += 1
|
|
|
|
end while (loc.path.start_with?(path) or (uplevel -= 1) >= 0)
|
|
|
|
uplevel = start
|
2018-09-23 23:14:43 -04:00
|
|
|
end
|
2018-09-24 09:04:40 -04:00
|
|
|
original_warn.call(*messages, uplevel: uplevel)
|
2018-09-23 23:14:43 -04:00
|
|
|
else
|
2018-09-24 09:04:40 -04:00
|
|
|
original_warn.call(*messages)
|
2018-09-23 23:14:43 -04:00
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|