File: container.rb

package info (click to toggle)
ruby-jwt 3.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 876 kB
  • sloc: ruby: 5,550; makefile: 4
file content (51 lines) | stat: -rw-r--r-- 1,801 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true

require_relative 'decode_configuration'
require_relative 'jwk_configuration'

module JWT
  module Configuration
    # The Container class holds the configuration settings for JWT.
    class Container
      # @!attribute [rw] decode
      #   @return [DecodeConfiguration] the decode configuration.
      # @!attribute [rw] jwk
      #   @return [JwkConfiguration] the JWK configuration.
      # @!attribute [rw] strict_base64_decoding
      #   @return [Boolean] whether strict Base64 decoding is enabled.
      attr_accessor :decode, :jwk, :strict_base64_decoding

      # @!attribute [r] deprecation_warnings
      #   @return [Symbol] the deprecation warnings setting.
      attr_reader :deprecation_warnings

      # Initializes a new Container instance and resets the configuration.
      def initialize
        reset!
      end

      # Resets the configuration to default values.
      #
      # @return [void]
      def reset!
        @decode                 = DecodeConfiguration.new
        @jwk                    = JwkConfiguration.new

        self.deprecation_warnings = :once
      end

      DEPRECATION_WARNINGS_VALUES = %i[once warn silent].freeze
      private_constant(:DEPRECATION_WARNINGS_VALUES)
      # Sets the deprecation warnings setting.
      #
      # @param value [Symbol] the deprecation warnings setting. Must be one of `:once`, `:warn`, or `:silent`.
      # @raise [ArgumentError] if the value is not one of the supported values.
      # @return [void]
      def deprecation_warnings=(value)
        raise ArgumentError, "Invalid deprecation_warnings value #{value}. Supported values: #{DEPRECATION_WARNINGS_VALUES}" unless DEPRECATION_WARNINGS_VALUES.include?(value)

        @deprecation_warnings = value
      end
    end
  end
end