Skip to content

Commit f93eb16

Browse files
committed
Improve Deprecation API docs and guide
- Link to Deprecation::Behavior in configuring guide The current list of options for `config.active_support.deprecation` was missing the newly added `:report` option. Instead of adding the missing option and continuing to keep 4 different lists of the same options in sync, I opted to replace the list with a link to the options in the Behavior API docs. This had the additional advantage of giving more information about all of the options which was not mentioned in the Configuring guide. - Use symbols for Behavior options It felt to me like naming the options did not make it explicit that those were the symbols to pass to `#behavior=`, but by adding the `:` that becomes more clear. - Add some API links There were a few references to `behavior=`, but we may as well link to the actual method.
1 parent 9064735 commit f93eb16

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

activesupport/lib/active_support/deprecation/behaviors.rb

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ class Deprecation
5757
# You can create a custom behavior or set any from the +DEFAULT_BEHAVIORS+
5858
# constant. Available behaviors are:
5959
#
60-
# [+raise+] Raise ActiveSupport::DeprecationException.
61-
# [+stderr+] Log all deprecation warnings to <tt>$stderr</tt>.
62-
# [+log+] Log all deprecation warnings to +Rails.logger+.
63-
# [+notify+] Use ActiveSupport::Notifications to notify +deprecation.rails+.
64-
# [+report+] Use ActiveSupport::ErrorReporter to report deprecations.
65-
# [+silence+] Do nothing. On \Rails, set <tt>config.active_support.report_deprecations = false</tt> to disable all behaviors.
60+
# [+:raise+] Raise ActiveSupport::DeprecationException.
61+
# [+:stderr+] Log all deprecation warnings to <tt>$stderr</tt>.
62+
# [+:log+] Log all deprecation warnings to +Rails.logger+.
63+
# [+:notify+] Use ActiveSupport::Notifications to notify +deprecation.rails+.
64+
# [+:report+] Use ActiveSupport::ErrorReporter to report deprecations.
65+
# [+:silence+] Do nothing. On \Rails, set <tt>config.active_support.report_deprecations = false</tt> to disable all behaviors.
6666
#
6767
# Setting behaviors only affects deprecations that happen after boot time.
68-
# For more information you can read the documentation of the +behavior=+ method.
68+
# For more information you can read the documentation of the #behavior= method.
6969
module Behavior
7070
# Whether to print a backtrace along with the warning.
7171
attr_accessor :debug
@@ -85,12 +85,12 @@ def disallowed_behavior
8585
#
8686
# Available behaviors:
8787
#
88-
# [+raise+] Raise ActiveSupport::DeprecationException.
89-
# [+stderr+] Log all deprecation warnings to <tt>$stderr</tt>.
90-
# [+log+] Log all deprecation warnings to +Rails.logger+.
91-
# [+notify+] Use ActiveSupport::Notifications to notify +deprecation.rails+.
92-
# [+report+] Use ActiveSupport::ErrorReporter to report deprecations.
93-
# [+silence+] Do nothing.
88+
# [+:raise+] Raise ActiveSupport::DeprecationException.
89+
# [+:stderr+] Log all deprecation warnings to <tt>$stderr</tt>.
90+
# [+:log+] Log all deprecation warnings to +Rails.logger+.
91+
# [+:notify+] Use ActiveSupport::Notifications to notify +deprecation.rails+.
92+
# [+:report+] Use ActiveSupport::ErrorReporter to report deprecations.
93+
# [+:silence+] Do nothing.
9494
#
9595
# Setting behaviors only affects deprecations that happen after boot time.
9696
# Deprecation warnings raised by gems are not affected by this setting
@@ -104,15 +104,17 @@ def disallowed_behavior
104104
# # custom stuff
105105
# }
106106
#
107-
# If you are using \Rails, you can set <tt>config.active_support.report_deprecations = false</tt> to disable
108-
# all deprecation behaviors. This is similar to the +silence+ option but more performant.
107+
# If you are using \Rails, you can set
108+
# <tt>config.active_support.report_deprecations = false</tt> to disable
109+
# all deprecation behaviors. This is similar to the +:silence+ option but
110+
# more performant.
109111
def behavior=(behavior)
110112
@behavior = Array(behavior).map { |b| DEFAULT_BEHAVIORS[b] || arity_coerce(b) }
111113
end
112114

113115
# Sets the behavior for disallowed deprecations (those configured by
114116
# ActiveSupport::Deprecation#disallowed_warnings=) to the specified
115-
# value. As with +behavior=+, this can be a single value, array, or an
117+
# value. As with #behavior=, this can be a single value, array, or an
116118
# object that responds to +call+.
117119
def disallowed_behavior=(behavior)
118120
@disallowed_behavior = Array(behavior).map { |b| DEFAULT_BEHAVIORS[b] || arity_coerce(b) }

guides/source/configuring.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,15 +2537,25 @@ The default value depends on the `config.load_defaults` target version:
25372537

25382538
#### `config.active_support.deprecation`
25392539

2540-
Configures the behavior of deprecation warnings. The options are `:raise`, `:stderr`, `:log`, `:notify`, and `:silence`.
2540+
Configures the behavior of deprecation warnings. See
2541+
[`Deprecation::Behavior`][deprecation_behavior] for a description of the
2542+
available options.
25412543

2542-
In the default generated `config/environments` files, this is set to `:log` for development and `:stderr` for test, and it is omitted for production in favor of [`config.active_support.report_deprecations`](#config-active-support-report-deprecations).
2544+
In the default generated `config/environments` files, this is set to `:log` for
2545+
development and `:stderr` for test, and it is omitted for production in favor of
2546+
[`config.active_support.report_deprecations`](#config-active-support-report-deprecations).
2547+
2548+
[deprecation_behavior]: https://api.rubyonrails.org/classes/ActiveSupport/Deprecation/Behavior.html#method-i-behavior-3D
25432549

25442550
#### `config.active_support.disallowed_deprecation`
25452551

2546-
Configures the behavior of disallowed deprecation warnings. The options are `:raise`, `:stderr`, `:log`, `:notify`, and `:silence`.
2552+
Configures the behavior of disallowed deprecation warnings. See
2553+
[`Deprecation::Behavior`][deprecation_behavior] for a description of the
2554+
available options.
25472555

2548-
In the default generated `config/environments` files, this is set to `:raise` for both development and test, and it is omitted for production in favor of [`config.active_support.report_deprecations`](#config-active-support-report-deprecations).
2556+
In the default generated `config/environments` files, this is set to `:raise`
2557+
for both development and test, and it is omitted for production in favor of
2558+
[`config.active_support.report_deprecations`](#config-active-support-report-deprecations).
25492559

25502560
#### `config.active_support.disallowed_deprecation_warnings`
25512561

0 commit comments

Comments
 (0)