Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

a little bit more tlc

  • Loading branch information...
commit 27c1eeb1c2a18c2ea3bb9e2c55e1d78dbb149f0a 1 parent e7c07a7
@joshk authored
View
25 lib/devise_suspendable/model.rb
@@ -7,17 +7,40 @@ module Models
# User.find(1).suspend!('Left the company')
#
module Suspendable
+ 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
def suspended?
self.suspended_at?
end
def suspend!(reason = nil)
- return if
+ return if suspended?
+ self.suspended_at = Time.zone.now
+ self.suspension_reason = reason
+ self.save(:validate = false)
end
def unsuspend!
+ return if !suspended?
+ self.suspended_at = nil
+ self.suspension_reason = nil
+ self.save(:validate = false) if self.changed?
+ end
+ # override Activatable
+ def active?
+ super && suspended?
end
end
end
View
4 lib/devise_suspendable/schema.rb
@@ -2,8 +2,8 @@
# Creates suspended_at and suspension_reason
def suspendable
- apply_schema :suspended_at, Time, :null => true
- apply_schema :suspension_reason, String, :null => true
+ apply_schema :suspended_at, DateTime, :null => true, :default => nil
+ apply_schema :suspension_reason, String, :null => true, :default => nil
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.