Class: ActiveRecord::TokenFor::TokenDefinition
- Inherits:
-
Struct
- Object
- Struct
- ActiveRecord::TokenFor::TokenDefinition
- Defined in:
- lib/active_record/token_for.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#defining_class ⇒ Object
Returns the value of attribute defining_class.
-
#expires_in ⇒ Object
Returns the value of attribute expires_in.
-
#purpose ⇒ Object
Returns the value of attribute purpose.
Instance Method Summary collapse
- #full_purpose ⇒ Object
- #generate_token(model) ⇒ Object
- #message_verifier ⇒ Object
- #payload_for(model) ⇒ Object
- #resolve_token(token) ⇒ Object
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block
14 15 16 |
# File 'lib/active_record/token_for.rb', line 14 def block @block end |
#defining_class ⇒ Object
Returns the value of attribute defining_class
14 15 16 |
# File 'lib/active_record/token_for.rb', line 14 def defining_class @defining_class end |
#expires_in ⇒ Object
Returns the value of attribute expires_in
14 15 16 |
# File 'lib/active_record/token_for.rb', line 14 def expires_in @expires_in end |
#purpose ⇒ Object
Returns the value of attribute purpose
14 15 16 |
# File 'lib/active_record/token_for.rb', line 14 def purpose @purpose end |
Instance Method Details
#full_purpose ⇒ Object
15 16 17 |
# File 'lib/active_record/token_for.rb', line 15 def full_purpose @full_purpose ||= [defining_class.name, purpose, expires_in].join("\n") end |
#generate_token(model) ⇒ Object
27 28 29 |
# File 'lib/active_record/token_for.rb', line 27 def generate_token(model) .generate(payload_for(model), expires_in: expires_in, purpose: full_purpose) end |
#message_verifier ⇒ Object
19 20 21 |
# File 'lib/active_record/token_for.rb', line 19 def defining_class.generated_token_verifier end |
#payload_for(model) ⇒ Object
23 24 25 |
# File 'lib/active_record/token_for.rb', line 23 def payload_for(model) block ? [model.id, model.instance_eval(&block).as_json] : [model.id] end |
#resolve_token(token) ⇒ Object
31 32 33 34 35 |
# File 'lib/active_record/token_for.rb', line 31 def resolve_token(token) payload = .verified(token, purpose: full_purpose) model = yield(payload[0]) if payload model if model && payload_for(model) == payload end |