Module: Devise::Models::Suspendable
- Defined in:
- lib/devise_suspendable/model.rb
Overview
Suspendable Module, responsible for manual deactivation of a user account.
Examples:
User.find(1).suspend!('Left the company')
Class Method Summary collapse
Instance Method Summary collapse
-
#active? ⇒ Boolean
override Activatable.
-
#inactive_message ⇒ Object
Overwrites invalid_message from Devise::Models::Authenticatable to define the correct reason for blocking the sign in.
- #suspend!(reason = nil) ⇒ Object
- #suspended? ⇒ Boolean
- #unsuspend! ⇒ Object
Class Method Details
.included(base) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/devise_suspendable/model.rb', line 10 def self.included(base) base.class_eval do validates_length_of :suspension_reason, :maximum => 250 # basic sanitization before_validation do |acc| acc.suspension_reason.strip! if acc.suspension_reason acc.suspension_reason = nil if acc.suspension_reason.blank? acc.suspension_reason = nil if acc.suspended_at.blank? end end end |
Instance Method Details
#active? ⇒ Boolean
override Activatable
42 43 44 |
# File 'lib/devise_suspendable/model.rb', line 42 def active? super && !suspended? end |
#inactive_message ⇒ Object
Overwrites invalid_message from Devise::Models::Authenticatable to define the correct reason for blocking the sign in.
48 49 50 |
# File 'lib/devise_suspendable/model.rb', line 48 def suspended? ? :suspended : super end |
#suspend!(reason = nil) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/devise_suspendable/model.rb', line 27 def suspend!(reason = nil) return if suspended? self.suspended_at = Time.zone.now self.suspension_reason = reason self.save(:validate => false) end |
#suspended? ⇒ Boolean
23 24 25 |
# File 'lib/devise_suspendable/model.rb', line 23 def suspended? self.suspended_at? end |
#unsuspend! ⇒ Object
34 35 36 37 38 39 |
# File 'lib/devise_suspendable/model.rb', line 34 def unsuspend! return if !suspended? self.suspended_at = nil self.suspension_reason = nil self.save(:validate => false) if self.changed? end |