module JWT::Deprecations

Deprecations module to handle deprecation warnings in the gem

Public Class Methods

context() { || ... } click to toggle source
# File lib/jwt/deprecations.rb, line 7
def context
  yield.tap { emit_warnings }
ensure
  Thread.current[:jwt_warning_store] = nil
end
emit_warnings() click to toggle source
# File lib/jwt/deprecations.rb, line 31
def emit_warnings
  return if Thread.current[:jwt_warning_store].nil?

  Thread.current[:jwt_warning_store].each { |warning| warn(warning) }
end
store(message) click to toggle source
# File lib/jwt/deprecations.rb, line 27
def store(message)
  (Thread.current[:jwt_warning_store] ||= []) << message
end
warning(message, only_if_valid: false) click to toggle source
# File lib/jwt/deprecations.rb, line 13
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

Private Class Methods

record_warned(message) click to toggle source
# File lib/jwt/deprecations.rb, line 39
def record_warned(message)
  @warned ||= []
  return true if @warned.include?(message)

  @warned << message
  false
end