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

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

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