instance method allow

Ruby on Rails 7.0.10

Since v6.1.7.10

Available in: v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

allow(allowed_warnings = :all, if: true, &block)

Allow previously disallowed deprecation warnings within the block. allowed_warnings can be an array containing strings, symbols, or regular expressions. (Symbols are treated as strings). These are compared against the text of deprecation warning messages generated within the block. Matching warnings will be exempt from the rules set by ActiveSupport::Deprecation.disallowed_warnings

The optional if: argument accepts a truthy/falsy value or an object that responds to .call. If truthy, then matching warnings will be allowed. If falsey then the method yields to the block without allowing the warning.

ActiveSupport::Deprecation.disallowed_behavior = :raise
ActiveSupport::Deprecation.disallowed_warnings = [
  "something broke"
]

ActiveSupport::Deprecation.warn('something broke!')
# => ActiveSupport::DeprecationException

ActiveSupport::Deprecation.allow ['something broke'] do
  ActiveSupport::Deprecation.warn('something broke!')
end
# => nil

ActiveSupport::Deprecation.allow ['something broke'], if: Rails.env.production? do
  ActiveSupport::Deprecation.warn('something broke!')
end
# => ActiveSupport::DeprecationException for dev/test, nil for production

Parameters

allowed_warnings opt = :all
if key = true
block block
Source
# File activesupport/lib/active_support/deprecation/reporting.rb, line 72
      def allow(allowed_warnings = :all, if: true, &block)
        conditional = binding.local_variable_get(:if)
        conditional = conditional.call if conditional.respond_to?(:call)
        if conditional
          @explicitly_allowed_warnings.bind(allowed_warnings, &block)
        else
          yield
        end
      end

Defined in activesupport/lib/active_support/deprecation/reporting.rb line 72 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::Deprecation::Reporting

Type at least 2 characters to search.

↑↓ navigate · open · esc close