module Devise::Models::Expirable::ClassMethods
Public Instance Methods
Version of {#delete_all_expired_for} without arguments (uses configured delete_expired_after
default value). @see delete_all_expired_for
# File lib/devise_security_extension/models/expirable.rb, line 114 def delete_all_expired delete_all_expired_for(delete_expired_after) end
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).
@example
Resource.delete_all_expired_for 90.days
@example You can overide this in your resource
model
def self.delete_all_expired_for(time = 90.days) puts 'overwritten delete call' end
@example Overwritten version to blank out the object.
def self.delete_all_expired_for(time = 90.days) expired_for(time).each do |u| u.update_attributes first_name: nil, last_name: nil end end
# File lib/devise_security_extension/models/expirable.rb, line 107 def delete_all_expired_for(time) expired_for(time).delete_all end
Scope method to collect all expired users since time
ago
# File lib/devise_security_extension/models/expirable.rb, line 81 def expired_for(time = delete_expired_after) where('expired_at < ?', time.ago) end
Sample method for daily cron to mark expired entries.
@example You can overide this in your resource
model
def self.mark_expired puts 'overwritten mark_expired' end
# File lib/devise_security_extension/models/expirable.rb, line 73 def mark_expired all.each do |u| u.expire! if u.expired? && u.expired_at.nil? end return end