Class: JWT::Token::Claim

Inherits:
Object
  • Object
show all
Defined in:
lib/jwt/token/claim.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, key, required, verifier) ⇒ Claim

Returns a new instance of Claim.



17
18
19
20
21
22
# File 'lib/jwt/token/claim.rb', line 17

def initialize(name, key, required, verifier)
  @name = name
  @key = key
  @required = required
  @verifier = verifier
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



15
16
17
# File 'lib/jwt/token/claim.rb', line 15

def key
  @key
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/jwt/token/claim.rb', line 15

def name
  @name
end

#requiredObject (readonly)

Returns the value of attribute required.



15
16
17
# File 'lib/jwt/token/claim.rb', line 15

def required
  @required
end

#verifierObject (readonly)

Returns the value of attribute verifier.



15
16
17
# File 'lib/jwt/token/claim.rb', line 15

def verifier
  @verifier
end

Instance Method Details

#verify(token, context = nil) ⇒ Object

Raises:



24
25
26
27
28
29
30
# File 'lib/jwt/token/claim.rb', line 24

def verify(token, context = nil)
  value = token.send(name)

  raise(MissingClaim, key) if required && value.nil?

  verifier.call(value, context) if value && verifier
end