Module: Devise::Models::Expirable::ClassMethods
- Defined in:
- lib/devise-security/models/expirable.rb
Instance Method Summary collapse
-
#delete_all_expired ⇒ Object
Version of #delete_all_expired_for without arguments (uses configured
delete_expired_after
default value). -
#delete_all_expired_for(time) ⇒ Object
Sample method for daily cron to delete all expired entries after a given amount of
time
. -
#expired_for(time = delete_expired_after) ⇒ Object
Scope method to collect all expired users since
time
ago. -
#mark_expired ⇒ Object
Sample method for daily cron to mark expired entries.
Instance Method Details
#delete_all_expired ⇒ Object
Version of #delete_all_expired_for without arguments (uses configured delete_expired_after
default value).
120 121 122 |
# File 'lib/devise-security/models/expirable.rb', line 120 def delete_all_expired delete_all_expired_for(delete_expired_after) end |
#delete_all_expired_for(time) ⇒ Object
Sample method for daily cron to delete all expired entries after a given amount of time
.
In your overwritten method you can “blank out” the object instead of deleting it.
*Word of warning*: You have to handle the dependent method on the resource
relations (:destroy
or :nullify
) and catch this behavior (see api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#label-Deleting+from+associations).
113 114 115 |
# File 'lib/devise-security/models/expirable.rb', line 113 def delete_all_expired_for(time) expired_for(time).delete_all end |
#expired_for(time = delete_expired_after) ⇒ Object
Scope method to collect all expired users since time
ago
87 88 89 |
# File 'lib/devise-security/models/expirable.rb', line 87 def expired_for(time = delete_expired_after) where('expired_at < ?', time.seconds.ago) end |
#mark_expired ⇒ Object
Sample method for daily cron to mark expired entries.
79 80 81 82 83 84 |
# File 'lib/devise-security/models/expirable.rb', line 79 def mark_expired all.each do |u| u.expire! if u.expired? && u.expired_at.nil? end return end |