1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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

This commit is contained in:
José Valim 2010-07-01 10:26:45 +02:00
parent f3fedd7f84
commit e596a8e14c
4 changed files with 19 additions and 3 deletions

View file

@ -1,4 +1,5 @@
require "active_support/notifications"
require "active_support/core_ext/array/wrap"
module ActiveSupport
module Deprecation
@ -11,7 +12,7 @@ module ActiveSupport
end
def behavior=(behavior)
@behavior = DEFAULT_BEHAVIORS[behavior] || behavior
@behavior = Array.wrap(behavior).map { |b| DEFAULT_BEHAVIORS[b] || b }
end
end

View file

@ -4,8 +4,9 @@ module ActiveSupport
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

View file

@ -1,6 +1,7 @@
require "active_support"
require "rails"
require "active_support/file_update_checker"
require "active_support/core_ext/array/wrap"
module I18n
class Railtie < Rails::Railtie

View file

@ -80,6 +80,19 @@ class DeprecationTest < ActiveSupport::TestCase
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 }