提交 e596a8e1 编写于 作者: J José Valim

Add the possibility to have several behaviors in AS::Deprecation.

上级 f3fedd7f
require "active_support/notifications"
require "active_support/core_ext/array/wrap"
module ActiveSupport
module Deprecation
......@@ -11,7 +12,7 @@ def behavior
end
def behavior=(behavior)
@behavior = DEFAULT_BEHAVIORS[behavior] || behavior
@behavior = Array.wrap(behavior).map { |b| DEFAULT_BEHAVIORS[b] || b }
end
end
......
......@@ -4,8 +4,9 @@ class << self
attr_accessor :silenced
def warn(message = nil, callstack = caller)
if behavior && !silenced
behavior.call(deprecation_message(callstack, message), callstack)
return if silenced
deprecation_message(callstack, message).tap do |m|
behavior.each { |b| b.call(m, callstack) }
end
end
......
require "active_support"
require "rails"
require "active_support/file_update_checker"
require "active_support/core_ext/array/wrap"
module I18n
class Railtie < Rails::Railtie
......
......@@ -80,6 +80,19 @@ def test_nil_behavior_is_ignored
assert_deprecated(/foo=nil/) { @dtc.partially }
end
def test_several_behaviors
@a, @b = nil, nil
ActiveSupport::Deprecation.behavior = [
Proc.new { |msg, callstack| @a = msg },
Proc.new { |msg, callstack| @b = msg }
]
@dtc.partially
assert_match(/foo=nil/, @a)
assert_match(/foo=nil/, @b)
end
def test_deprecated_instance_variable_proxy
assert_not_deprecated { @dtc.request.size }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册