Guest User

Untitled

a guest
Apr 25th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. acts_as_state_machine :initial => :pending
  2. state :passive
  3. state :pending, :enter => :make_activation_code
  4. state :active, :enter => :do_activate
  5. state :suspended
  6. state :deleted, :enter => :do_delete
  7.  
  8. event :register do
  9. transitions :from => :passive, :to => :pending, :guard => Proc.new {|u| !(u.crypted_password.blank? && u.password.blank?) }
  10. end
  11.  
  12. event :activate do
  13. transitions :from => :pending, :to => :active
  14. end
  15.  
  16. event :suspend do
  17. transitions :from => [:passive, :pending, :active], :to => :suspended
  18. end
  19.  
  20. event :delete do
  21. transitions :from => [:passive, :pending, :active, :suspended], :to => :deleted
  22. end
  23.  
  24. event :unsuspend do
  25. transitions :from => :suspended, :to => :active, :guard => Proc.new {|u| !u.activated_at.blank? }
  26. transitions :from => :suspended, :to => :pending, :guard => Proc.new {|u| !u.activation_code.blank? }
  27. transitions :from => :suspended, :to => :passive
  28. end
Add Comment
Please, Sign In to add comment