Module: Doorkeeper::Models::Expirable

Included in:
AccessGrantMixin, AccessTokenMixin
Defined in:
lib/doorkeeper/models/concerns/expirable.rb

Instance Method Summary collapse

Instance Method Details

#expired?Boolean

Indicates whether the object is expired (‘#expires_in` present and expiration time has come).



10
11
12
# File 'lib/doorkeeper/models/concerns/expirable.rb', line 10

def expired?
  expires_in && Time.now.utc > expires_at
end

#expires_atTime?

Expiration time (date time of creation + TTL).



31
32
33
# File 'lib/doorkeeper/models/concerns/expirable.rb', line 31

def expires_at
  expires_in && created_at + expires_in.seconds
end

#expires_in_secondsInteger?

Calculates expiration time in seconds.



18
19
20
21
22
23
24
# File 'lib/doorkeeper/models/concerns/expirable.rb', line 18

def expires_in_seconds
  return nil if expires_in.nil?

  expires = expires_at - Time.now.utc
  expires_sec = expires.seconds.round(0)
  expires_sec > 0 ? expires_sec : 0
end