Sha256: 9267b23d9661590cba236189cb2e08c158eee7245db3205d356e73abd1acc8d3

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module JWT
  # Deprecations module to handle deprecation warnings in the gem
  # @api private
  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

3 entries across 3 versions & 2 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/jwt-2.10.1/lib/jwt/deprecations.rb
jwt-2.10.1 lib/jwt/deprecations.rb
jwt-2.10.0 lib/jwt/deprecations.rb