Class: JWT::JWK::Set
- Inherits:
-
Object
- Object
- JWT::JWK::Set
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/jwt/jwk/set.rb
Instance Attribute Summary collapse
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #add(key) ⇒ Object (also: #<<)
- #export(options = {}) ⇒ Object
-
#initialize(jwks = nil, options = {}) ⇒ Set
constructor
rubocop:disable Metrics/CyclomaticComplexity.
- #merge(enum) ⇒ Object
- #reject!(&block) ⇒ Object
- #select!(&block) ⇒ Object (also: #filter!)
- #union(enum) ⇒ Object (also: #|, #+)
- #uniq!(&block) ⇒ Object
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, = {}) # 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, ) } when Array jwks.map { |k| JWT::JWK.new(k, nil, ) } else raise ArgumentError, 'Can only create new JWKS from Hash, Array and JWK' end end |
Instance Attribute Details
#keys ⇒ Object (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( = {}) { keys: @keys.map { |k| k.export() } } 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 |