Class: SecureToken

Inherits:
Object
  • Object
show all
Defined in:
app/models/secure_token.rb

Constant Summary collapse

EXPIRES_IN =
30

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#expires_atObject



24
# File 'app/models/secure_token.rb', line 24

def expires_at; @expires_at ||= EXPIRES_IN.minutes.from_now end

#tokenObject



20
# File 'app/models/secure_token.rb', line 20

def token; @token ||= String.secure_token end

Class Method Details

.by_token(token) ⇒ Object Also known as: first_by_token



34
35
36
37
# File 'app/models/secure_token.rb', line 34

def by_token token
  return nil if token.blank?
  first token: token, expires_at: {_gte: Time.now.utc}
end

.by_token!(token) ⇒ Object Also known as: first_by_token!



40
41
42
# File 'app/models/secure_token.rb', line 40

def by_token! token
  return by_token(token) || raise(Mongo::NotFound, "token #{token} not found!")
end

Instance Method Details

#[](k) ⇒ Object

attr_writer :values def values; @values ||= {} end



12
13
14
# File 'app/models/secure_token.rb', line 12

def [] k
  instance_variable_get :"@#{k}"
end

#[]=(k, v) ⇒ Object



15
16
17
# File 'app/models/secure_token.rb', line 15

def []= k, v
  instance_variable_set :"@#{k}", v
end

#expired?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/models/secure_token.rb', line 29

def expired?
  expires_at >= Time.now.utc
end