提交 211f55d4 编写于 作者: A Aaron Patterson

use `caller_locations` instead of `caller`

We have `caller_locations`, so we don't need to parse the strings in the
callstack.
上级 c82248ea
......@@ -20,7 +20,7 @@ def inspect
private
def method_missing(called, *args, &block)
warn caller, called, args
warn caller_locations, called, args
target.__send__(called, *args, &block)
end
end
......
......@@ -14,7 +14,7 @@ module Reporting
def warn(message = nil, callstack = nil)
return if silenced
callstack ||= caller(2)
callstack ||= caller_locations(2)
deprecation_message(callstack, message).tap do |m|
behavior.each { |b| b.call(m, callstack) }
end
......@@ -37,7 +37,7 @@ def silence
end
def deprecation_warning(deprecated_method_name, message = nil, caller_backtrace = nil)
caller_backtrace ||= caller(2)
caller_backtrace ||= caller_locations(2)
deprecated_method_warning(deprecated_method_name, message).tap do |msg|
warn(msg, caller_backtrace)
end
......@@ -79,6 +79,17 @@ def deprecation_caller_message(callstack)
end
def extract_callstack(callstack)
return _extract_callstack(callstack) if callstack.first.is_a? String
rails_gem_root = File.expand_path("../../../../..", __FILE__) + "/"
offending_line = callstack.find { |frame|
!frame.absolute_path.start_with?(rails_gem_root)
} || callstack.first
[offending_line.path, offending_line.lineno, offending_line.label]
end
def _extract_callstack(callstack)
warn "Please pass `caller_locations` to the deprecation API" if $VERBOSE
rails_gem_root = File.expand_path("../../../../..", __FILE__) + "/"
offending_line = callstack.find { |line| !line.start_with?(rails_gem_root) } || callstack.first
if offending_line
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册