Module: ActiveRecord::TokenFor::RelationMethods
- Included in:
- Relation
- Defined in:
- lib/active_record/token_for.rb
Instance Method Summary collapse
-
#find_by_token_for(purpose, token) ⇒ Object
Finds a record using a given
token
for a predefinedpurpose
. -
#find_by_token_for!(purpose, token) ⇒ Object
Finds a record using a given
token
for a predefinedpurpose
.
Instance Method Details
#find_by_token_for(purpose, token) ⇒ Object
Finds a record using a given token
for a predefined purpose
. Returns nil
if the token is invalid or the record was not found.
41 42 43 44 |
# File 'lib/active_record/token_for.rb', line 41 def find_by_token_for(purpose, token) raise UnknownPrimaryKey.new(self) unless model.primary_key model.token_definitions.fetch(purpose).resolve_token(token) { |id| find_by(model.primary_key => id) } end |
#find_by_token_for!(purpose, token) ⇒ Object
Finds a record using a given token
for a predefined purpose
. Raises ActiveSupport::MessageVerifier::InvalidSignature if the token is invalid (e.g. expired, bad format, etc). Raises ActiveRecord::RecordNotFound if the token is valid but the record was not found.
50 51 52 53 |
# File 'lib/active_record/token_for.rb', line 50 def find_by_token_for!(purpose, token) model.token_definitions.fetch(purpose).resolve_token(token) { |id| find(id) } || (raise ActiveSupport::MessageVerifier::InvalidSignature) end |