Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37940 from cpruitt/activesupport-disallowed-depre…
…cations Introduce ActiveSupport Disallowed Deprecations
- Loading branch information
Showing
10 changed files
with
582 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
activesupport/lib/active_support/deprecation/disallowed.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActiveSupport | ||
class Deprecation | ||
module Disallowed | ||
# Sets the criteria used to identify deprecation messages which should be | ||
# disallowed. Can be an array containing strings, symbols, or regular | ||
# expressions. (Symbols are treated as strings). These are compared against | ||
# the text of the generated deprecation warning. | ||
# | ||
# Additionally the scalar symbol +:all+ may be used to treat all | ||
# deprecations as disallowed. | ||
# | ||
# Deprecations matching a substring or regular expression will be handled | ||
# using the configured +ActiveSupport::Deprecation.disallowed_behavior+ | ||
# rather than +ActiveSupport::Deprecation.behavior+ | ||
attr_writer :disallowed_warnings | ||
|
||
# Returns the configured criteria used to identify deprecation messages | ||
# which should be treated as disallowed. | ||
def disallowed_warnings | ||
@disallowed_warnings ||= [] | ||
end | ||
|
||
private | ||
def deprecation_disallowed?(message) | ||
disallowed = ActiveSupport::Deprecation.disallowed_warnings | ||
return false if explicitly_allowed?(message) | ||
return true if disallowed == :all | ||
disallowed.any? do |rule| | ||
case rule | ||
when String, Symbol | ||
message.include?(rule.to_s) | ||
when Regexp | ||
rule.match(message) | ||
end | ||
end | ||
end | ||
|
||
def explicitly_allowed?(message) | ||
allowances = @explicitly_allowed_warnings.value | ||
return false unless allowances | ||
return true if allowances == :all | ||
allowances = [allowances] unless allowances.kind_of?(Array) | ||
allowances.any? do |rule| | ||
case rule | ||
when String, Symbol | ||
message.include?(rule.to_s) | ||
when Regexp | ||
rule.match(message) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.