Class: JWT::JWK::Set

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/jwt/jwk/set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(jwks = nil, options = {}) ⇒ Set

rubocop:disable Metrics/CyclomaticComplexity



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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

Instance Attribute Details

#keysObject (readonly)

Returns the value of attribute keys.



11
12
13
# File 'lib/jwt/jwk/set.rb', line 11

def keys
  @keys
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



67
68
69
# File 'lib/jwt/jwk/set.rb', line 67

def ==(other)
  other.is_a?(JWT::JWK::Set) && keys.sort == other.keys.sort
end

#add(key) ⇒ Object Also known as: <<



62
63
64
65
# File 'lib/jwt/jwk/set.rb', line 62

def add(key)
  @keys << JWT::JWK.new(key)
  self
end

#export(options = {}) ⇒ Object



31
32
33
# File 'lib/jwt/jwk/set.rb', line 31

def export(options = {})
  { keys: @keys.map { |k| k.export(options) } }
end

#merge(enum) ⇒ Object



53
54
55
56
# File 'lib/jwt/jwk/set.rb', line 53

def merge(enum)
  @keys += JWT::JWK::Set.new(enum.to_a).keys
  self
end

#reject!(&block) ⇒ Object



43
44
45
46
47
# File 'lib/jwt/jwk/set.rb', line 43

def reject!(&block)
  return @keys.reject! unless block

  self if @keys.reject!(&block)
end

#select!(&block) ⇒ Object Also known as: filter!



37
38
39
40
41
# File 'lib/jwt/jwk/set.rb', line 37

def select!(&block)
  return @keys.select! unless block

  self if @keys.select!(&block)
end

#union(enum) ⇒ Object Also known as: |, +



58
59
60
# File 'lib/jwt/jwk/set.rb', line 58

def union(enum)
  dup.merge(enum)
end

#uniq!(&block) ⇒ Object



49
50
51
# File 'lib/jwt/jwk/set.rb', line 49

def uniq!(&block)
  self if @keys.uniq!(&block)
end