diff options
author | Xavier Noria <fxn@hashref.com> | 2013-08-12 23:23:21 +0000 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2013-08-13 01:27:18 +0200 |
commit | 73aad75f5665607e1abc2cf0a69460a923bbd571 (patch) | |
tree | 79f528f24975a4ec2a0458c73d6ff7484045d040 /activesupport/lib | |
parent | 1577d9661a9ee0268d9f101c6c7f6435a87e8de0 (diff) | |
download | rails-73aad75f5665607e1abc2cf0a69460a923bbd571.tar.gz rails-73aad75f5665607e1abc2cf0a69460a923bbd571.tar.bz2 rails-73aad75f5665607e1abc2cf0a69460a923bbd571.zip |
defines a new :abort deprecation behaviour that raises
See the CHANGELONG message in the patch for further details.
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/deprecation/behaviors.rb | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/deprecation/behaviors.rb b/activesupport/lib/active_support/deprecation/behaviors.rb index 90db180124..8c7d80c134 100644 --- a/activesupport/lib/active_support/deprecation/behaviors.rb +++ b/activesupport/lib/active_support/deprecation/behaviors.rb @@ -1,14 +1,24 @@ require "active_support/notifications" module ActiveSupport + class DeprecationException < StandardError + end + class Deprecation # Default warning behaviors per Rails.env. DEFAULT_BEHAVIORS = { - :stderr => Proc.new { |message, callstack| + abort: ->(message, callstack) { + e = DeprecationException.new(message) + e.set_backtrace(callstack) + raise e + }, + + stderr: ->(message, callstack) { $stderr.puts(message) $stderr.puts callstack.join("\n ") if debug }, - :log => Proc.new { |message, callstack| + + log: ->(message, callstack) { logger = if defined?(Rails) && Rails.logger Rails.logger @@ -19,11 +29,13 @@ module ActiveSupport logger.warn message logger.debug callstack.join("\n ") if debug }, - :notify => Proc.new { |message, callstack| + + notify: ->(message, callstack) { ActiveSupport::Notifications.instrument("deprecation.rails", :message => message, :callstack => callstack) }, - :silence => Proc.new { |message, callstack| } + + silence: ->(message, callstack) {}, } module Behavior @@ -40,6 +52,7 @@ module ActiveSupport # # Available behaviors: # + # [+abort+] Raises <tt>ActiveSupport::DeprecationException</tt>. # [+stderr+] Log all deprecation warnings to +$stderr+. # [+log+] Log all deprecation warnings to +Rails.logger+. # [+notify+] Use +ActiveSupport::Notifications+ to notify +deprecation.rails+. @@ -52,7 +65,7 @@ module ActiveSupport # ActiveSupport::Deprecation.behavior = :stderr # ActiveSupport::Deprecation.behavior = [:stderr, :log] # ActiveSupport::Deprecation.behavior = MyCustomHandler - # ActiveSupport::Deprecation.behavior = proc { |message, callstack| + # ActiveSupport::Deprecation.behavior = ->(message, callstack) { # # custom stuff # } def behavior=(behavior) |