Sha256: 7c5215e672abeee711bb4fa8b2be10bb1e6cb2f1a964830580d1459e56d0d5f1

Contents?: true

Size: 1.08 KB

Versions: 6

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module JWT
  # Deprecations module to handle deprecation warnings in the gem
  module Deprecations
    class << self
      def context
        yield.tap { emit_warnings }
      ensure
        Thread.current[:jwt_warning_store] = nil
      end

      def warning(message, only_if_valid: false)
        method_name = only_if_valid ? :store : :warn
        case JWT.configuration.deprecation_warnings
        when :once
          return if record_warned(message)
        when :warn
          # noop
        else
          return
        end

        send(method_name, "[DEPRECATION WARNING] #{message}")
      end

      def store(message)
        (Thread.current[:jwt_warning_store] ||= []) << message
      end

      def emit_warnings
        return if Thread.current[:jwt_warning_store].nil?

        Thread.current[:jwt_warning_store].each { |warning| warn(warning) }
      end

      private

      def record_warned(message)
        @warned ||= []
        return true if @warned.include?(message)

        @warned << message
        false
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
jwt-2.9.3 lib/jwt/deprecations.rb
jwt-2.9.2 lib/jwt/deprecations.rb
jwt-2.9.1 lib/jwt/deprecations.rb
jwt-2.9.0 lib/jwt/deprecations.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/jwt-2.8.2/lib/jwt/deprecations.rb
jwt-2.8.2 lib/jwt/deprecations.rb