module ActiveSupport::Deprecation::Behavior
def arity_coerce(behavior)
def arity_coerce(behavior) unless behavior.respond_to?(:call) raise ArgumentError, "#{behavior.inspect} is not a valid deprecation behavior." end if behavior.respond_to?(:arity) && behavior.arity == 2 -> message, callstack, _, _ { behavior.call(message, callstack) } else behavior end end
def behavior
def behavior @behavior ||= [DEFAULT_BEHAVIORS[:stderr]] end
def behavior=(behavior)
If you are using Rails, you can set config.active_support.report_deprecations = false to disable
}
# custom stuff
ActiveSupport::Deprecation.behavior = ->(message, callstack, deprecation_horizon, gem_name) {
ActiveSupport::Deprecation.behavior = MyCustomHandler
ActiveSupport::Deprecation.behavior = [:stderr, :log]
ActiveSupport::Deprecation.behavior = :stderr
because they happen before Rails boots up.
Deprecation warnings raised by gems are not affected by this setting
Setting behaviors only affects deprecations that happen after boot time.
[+silence+] Do nothing.
[+notify+] Use +ActiveSupport::Notifications+ to notify +deprecation.rails+.
[+log+] Log all deprecation warnings to +Rails.logger+.
[+stderr+] Log all deprecation warnings to $stderr.
[+raise+] Raise ActiveSupport::DeprecationException.
Available behaviors:
or an object that responds to +call+.
Sets the behavior to the specified value. Can be a single value, array,
def behavior=(behavior) @behavior = Array(behavior).map { |b| DEFAULT_BEHAVIORS[b] || arity_coerce(b) } end
def disallowed_behavior
def disallowed_behavior @disallowed_behavior ||= [DEFAULT_BEHAVIORS[:raise]] end
def disallowed_behavior=(behavior)
value. As with +behavior=+, this can be a single value, array, or an
ActiveSupport::Deprecation.disallowed_warnings=) to the specified
Sets the behavior for disallowed deprecations (those configured by
def disallowed_behavior=(behavior) @disallowed_behavior = Array(behavior).map { |b| DEFAULT_BEHAVIORS[b] || arity_coerce(b) } end