diff options
author | Willem van Bergen <willem@vanbergen.org> | 2017-04-19 14:50:25 -0400 |
---|---|---|
committer | Willem van Bergen <willem@vanbergen.org> | 2017-04-19 18:23:28 -0400 |
commit | 0bdf6d757bbfd5495c84ca98520d9f7fb48893bd (patch) | |
tree | a946d04c76abad07858a15d7abdb42f931124890 /activesupport/lib/active_support/deprecation | |
parent | c324f5d8bbd717b308776bf47a5fed83ce691e66 (diff) | |
download | rails-0bdf6d757bbfd5495c84ca98520d9f7fb48893bd.tar.gz rails-0bdf6d757bbfd5495c84ca98520d9f7fb48893bd.tar.bz2 rails-0bdf6d757bbfd5495c84ca98520d9f7fb48893bd.zip |
Send deprecation horizon and gem name as arguments to deprecation heavier handler, and make sure they are used for the ActiveSupport::Notifications message.
Diffstat (limited to 'activesupport/lib/active_support/deprecation')
-rw-r--r-- | activesupport/lib/active_support/deprecation/behaviors.rb | 29 | ||||
-rw-r--r-- | activesupport/lib/active_support/deprecation/reporting.rb | 2 |
2 files changed, 22 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/deprecation/behaviors.rb b/activesupport/lib/active_support/deprecation/behaviors.rb index 1d1354c23e..a9a182f212 100644 --- a/activesupport/lib/active_support/deprecation/behaviors.rb +++ b/activesupport/lib/active_support/deprecation/behaviors.rb @@ -9,18 +9,18 @@ module ActiveSupport class Deprecation # Default warning behaviors per Rails.env. DEFAULT_BEHAVIORS = { - raise: ->(message, callstack) { + raise: ->(message, callstack, deprecation_horizon, gem_name) { e = DeprecationException.new(message) e.set_backtrace(callstack.map(&:to_s)) raise e }, - stderr: ->(message, callstack) { + stderr: ->(message, callstack, deprecation_horizon, gem_name) { $stderr.puts(message) $stderr.puts callstack.join("\n ") if debug }, - log: ->(message, callstack) { + log: ->(message, callstack, deprecation_horizon, gem_name) { logger = if defined?(Rails.logger) && Rails.logger Rails.logger @@ -32,12 +32,16 @@ module ActiveSupport logger.debug callstack.join("\n ") if debug }, - notify: ->(message, callstack) { - ActiveSupport::Notifications.instrument("deprecation.rails", - message: message, callstack: callstack) + notify: ->(message, callstack, deprecation_horizon, gem_name) { + notification_name = "deprecation.#{gem_name.underscore.tr('/', '_')}" + ActiveSupport::Notifications.instrument(notification_name, + message: message, + callstack: callstack, + gem_name: gem_name, + deprecation_horizon: deprecation_horizon) }, - silence: ->(message, callstack) {}, + silence: ->(message, callstack, deprecation_horizon, gem_name) {}, } # Behavior module allows to determine how to display deprecation messages. @@ -83,8 +87,17 @@ module ActiveSupport # # custom stuff # } def behavior=(behavior) - @behavior = Array(behavior).map { |b| DEFAULT_BEHAVIORS[b] || b } + @behavior = Array(behavior).map { |b| DEFAULT_BEHAVIORS[b] || arity_coerce(b) } end + + private + def arity_coerce(behavior) + if behavior.arity == 4 || behavior.arity == -1 + behavior + else + -> message, callstack, _, _ { behavior.call(message, callstack) } + end + end end end end diff --git a/activesupport/lib/active_support/deprecation/reporting.rb b/activesupport/lib/active_support/deprecation/reporting.rb index 58c5c50e30..851d8eeda1 100644 --- a/activesupport/lib/active_support/deprecation/reporting.rb +++ b/activesupport/lib/active_support/deprecation/reporting.rb @@ -18,7 +18,7 @@ module ActiveSupport callstack ||= caller_locations(2) deprecation_message(callstack, message).tap do |m| - behavior.each { |b| b.call(m, callstack) } + behavior.each { |b| b.call(m, callstack, deprecation_horizon, gem_name) } end end |