mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
use caller_locations
instead of caller
We have `caller_locations`, so we don't need to parse the strings in the callstack.
This commit is contained in:
parent
c82248ea86
commit
211f55d4fd
2 changed files with 14 additions and 3 deletions
|
@ -20,7 +20,7 @@ module ActiveSupport
|
||||||
|
|
||||||
private
|
private
|
||||||
def method_missing(called, *args, &block)
|
def method_missing(called, *args, &block)
|
||||||
warn caller, called, args
|
warn caller_locations, called, args
|
||||||
target.__send__(called, *args, &block)
|
target.__send__(called, *args, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,7 @@ module ActiveSupport
|
||||||
def warn(message = nil, callstack = nil)
|
def warn(message = nil, callstack = nil)
|
||||||
return if silenced
|
return if silenced
|
||||||
|
|
||||||
callstack ||= caller(2)
|
callstack ||= caller_locations(2)
|
||||||
deprecation_message(callstack, message).tap do |m|
|
deprecation_message(callstack, message).tap do |m|
|
||||||
behavior.each { |b| b.call(m, callstack) }
|
behavior.each { |b| b.call(m, callstack) }
|
||||||
end
|
end
|
||||||
|
@ -37,7 +37,7 @@ module ActiveSupport
|
||||||
end
|
end
|
||||||
|
|
||||||
def deprecation_warning(deprecated_method_name, message = nil, caller_backtrace = nil)
|
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|
|
deprecated_method_warning(deprecated_method_name, message).tap do |msg|
|
||||||
warn(msg, caller_backtrace)
|
warn(msg, caller_backtrace)
|
||||||
end
|
end
|
||||||
|
@ -79,6 +79,17 @@ module ActiveSupport
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract_callstack(callstack)
|
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__) + "/"
|
rails_gem_root = File.expand_path("../../../../..", __FILE__) + "/"
|
||||||
offending_line = callstack.find { |line| !line.start_with?(rails_gem_root) } || callstack.first
|
offending_line = callstack.find { |line| !line.start_with?(rails_gem_root) } || callstack.first
|
||||||
if offending_line
|
if offending_line
|
||||||
|
|
Loading…
Reference in a new issue