123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::TokenFor::TokenDefinition

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ::Struct
Instance Chain:
self, ::Struct
Inherits: Struct
Defined in: activerecord/lib/active_record/token_for.rb

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#block (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/token_for.rb', line 14

TokenDefinition = Struct.new(:defining_class, :purpose, :expires_in, :block)

#defining_class (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/token_for.rb', line 14

TokenDefinition = Struct.new(:defining_class, :purpose, :expires_in, :block)

#expires_in (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/token_for.rb', line 14

TokenDefinition = Struct.new(:defining_class, :purpose, :expires_in, :block)

#purpose (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/token_for.rb', line 14

TokenDefinition = Struct.new(:defining_class, :purpose, :expires_in, :block)

Instance Method Details

#full_purpose

[ GitHub ]

  
# File 'activerecord/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)

[ GitHub ]

  
# File 'activerecord/lib/active_record/token_for.rb', line 27

def generate_token(model)
  message_verifier.generate(payload_for(model), expires_in: expires_in, purpose: full_purpose)
end

#message_verifier

[ GitHub ]

  
# File 'activerecord/lib/active_record/token_for.rb', line 19

def message_verifier
  defining_class.generated_token_verifier
end

#payload_for(model)

[ GitHub ]

  
# File 'activerecord/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)

[ GitHub ]

  
# File 'activerecord/lib/active_record/token_for.rb', line 31

def resolve_token(token)
  payload = message_verifier.verified(token, purpose: full_purpose)
  model = yield(payload[0]) if payload
  model if model && payload_for(model) == payload
end