Sha256: ef16cf8212b8da46163844abc04f86255d6b95cab1864dc436211d511d4104dc

Contents?: true

Size: 1.89 KB

Versions: 69

Compression:

Stored size: 1.89 KB

Contents

# 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

Version data entries

69 entries across 65 versions & 9 rubygems

Version Path
activesupport-6.1.7.10 lib/active_support/deprecation/disallowed.rb
activesupport-6.1.7.9 lib/active_support/deprecation/disallowed.rb
activesupport-6.1.7.8 lib/active_support/deprecation/disallowed.rb
activesupport-6.1.7.7 lib/active_support/deprecation/disallowed.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activesupport-7.0.2.3/lib/active_support/deprecation/disallowed.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activesupport-7.0.3.1/lib/active_support/deprecation/disallowed.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activesupport-6.1.6.1/lib/active_support/deprecation/disallowed.rb
activesupport-6.1.7.6 lib/active_support/deprecation/disallowed.rb
activesupport-6.1.7.5 lib/active_support/deprecation/disallowed.rb
activesupport-6.1.7.4 lib/active_support/deprecation/disallowed.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activesupport-6.1.6.1/lib/active_support/deprecation/disallowed.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activesupport-7.0.2.3/lib/active_support/deprecation/disallowed.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activesupport-7.0.3.1/lib/active_support/deprecation/disallowed.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/deprecation/disallowed.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/activesupport-7.0.4.3/lib/active_support/deprecation/disallowed.rb
activesupport-7.0.4.3 lib/active_support/deprecation/disallowed.rb
activesupport-6.1.7.3 lib/active_support/deprecation/disallowed.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/deprecation/disallowed.rb
activesupport-6.1.7.2 lib/active_support/deprecation/disallowed.rb
activesupport-7.0.4.2 lib/active_support/deprecation/disallowed.rb