aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/deprecation.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/deprecation.rb')
-rw-r--r--activesupport/lib/active_support/deprecation.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/deprecation.rb b/activesupport/lib/active_support/deprecation.rb
index d6c9317f06..99c27ee9d1 100644
--- a/activesupport/lib/active_support/deprecation.rb
+++ b/activesupport/lib/active_support/deprecation.rb
@@ -9,13 +9,27 @@ module ActiveSupport
class << self
def warn(message = nil, callstack = caller)
- behavior.call(deprecation_message(callstack, message)) if behavior
+ behavior.call(deprecation_message(callstack, message)) if behavior && ! silenced?
end
def default_behavior
DEFAULT_BEHAVIORS[RAILS_ENV.to_s] if defined?(RAILS_ENV)
end
+ # Have deprecations been silenced?
+ def silenced?
+ @silenced
+ end
+
+ # Silence deprecations for the duration of the provided block. For internal
+ # use only.
+ def silence
+ old_silenced, @silenced = @silenced, true # We could have done behavior = nil...
+ yield
+ ensure
+ @silenced = old_silenced
+ end
+
private
def deprecation_message(callstack, message = nil)
file, line, method = extract_callstack(callstack)