class JWT::JWK::Set

Attributes

keys[R]

Public Class Methods

new(jwks = nil, options = {}) click to toggle source
# File lib/jwt/jwk/set.rb, line 13
def initialize(jwks = nil, options = {}) # rubocop:disable Metrics/CyclomaticComplexity
  jwks ||= {}

  @keys = case jwks
          when JWT::JWK::Set # Simple duplication
            jwks.keys
          when JWT::JWK::KeyBase # Singleton
            [jwks]
          when Hash
            jwks = jwks.transform_keys(&:to_sym)
            [*jwks[:keys]].map { |k| JWT::JWK.new(k, nil, options) }
          when Array
            jwks.map { |k| JWT::JWK.new(k, nil, options) }
          else
            raise ArgumentError, 'Can only create new JWKS from Hash, Array and JWK'
          end
end

Public Instance Methods

+(enum)
Alias for: union
<<(key)
Alias for: add
==(other) click to toggle source
# File lib/jwt/jwk/set.rb, line 67
def ==(other)
  other.is_a?(JWT::JWK::Set) && keys.sort == other.keys.sort
end
Also aliased as: eql?
add(key) click to toggle source
# File lib/jwt/jwk/set.rb, line 62
def add(key)
  @keys << JWT::JWK.new(key)
  self
end
Also aliased as: <<
eql?(other)
Alias for: ==
export(options = {}) click to toggle source
# File lib/jwt/jwk/set.rb, line 31
def export(options = {})
  { keys: @keys.map { |k| k.export(options) } }
end
filter!(&block)
Alias for: select!
merge(enum) click to toggle source
# File lib/jwt/jwk/set.rb, line 53
def merge(enum)
  @keys += JWT::JWK::Set.new(enum.to_a).keys
  self
end
reject!(&block) click to toggle source
# File lib/jwt/jwk/set.rb, line 43
def reject!(&block)
  return @keys.reject! unless block

  self if @keys.reject!(&block)
end
select!(&block) click to toggle source
# File lib/jwt/jwk/set.rb, line 37
def select!(&block)
  return @keys.select! unless block

  self if @keys.select!(&block)
end
Also aliased as: filter!
union(enum) click to toggle source
# File lib/jwt/jwk/set.rb, line 58
def union(enum)
  dup.merge(enum)
end
Also aliased as: |, +
uniq!(&block) click to toggle source
# File lib/jwt/jwk/set.rb, line 49
def uniq!(&block)
  self if @keys.uniq!(&block)
end
|(enum)

For symbolic manipulation

Alias for: union