Class: ActiveRecord::TokenFor::TokenDefinition
- Defined in:
- activerecord/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
Methods inherited from Struct
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block
15 16 17 |
# File 'activerecord/lib/active_record/token_for.rb', line 15 def block @block end |
#defining_class ⇒ Object
Returns the value of attribute defining_class
15 16 17 |
# File 'activerecord/lib/active_record/token_for.rb', line 15 def defining_class @defining_class end |
#expires_in ⇒ Object
Returns the value of attribute expires_in
15 16 17 |
# File 'activerecord/lib/active_record/token_for.rb', line 15 def expires_in @expires_in end |
#purpose ⇒ Object
Returns the value of attribute purpose
15 16 17 |
# File 'activerecord/lib/active_record/token_for.rb', line 15 def purpose @purpose end |
Instance Method Details
#full_purpose ⇒ Object
16 17 18 |
# File 'activerecord/lib/active_record/token_for.rb', line 16 def full_purpose @full_purpose ||= [defining_class.name, purpose, expires_in].join("\n") end |
#generate_token(model) ⇒ Object
28 29 30 |
# File 'activerecord/lib/active_record/token_for.rb', line 28 def generate_token(model) .generate(payload_for(model), expires_in: expires_in, purpose: full_purpose) end |
#message_verifier ⇒ Object
20 21 22 |
# File 'activerecord/lib/active_record/token_for.rb', line 20 def defining_class.generated_token_verifier end |
#payload_for(model) ⇒ Object
24 25 26 |
# File 'activerecord/lib/active_record/token_for.rb', line 24 def payload_for(model) block ? [model.id, model.instance_eval(&block).as_json] : [model.id] end |
#resolve_token(token) ⇒ Object
32 33 34 35 36 |
# File 'activerecord/lib/active_record/token_for.rb', line 32 def resolve_token(token) payload = .verified(token, purpose: full_purpose) model = yield(payload[0]) if payload model if model && payload_for(model) == payload end |