Module: Authorization::AasmRoles

Defined in:
lib/authorization/aasm_roles.rb

Defined Under Namespace

Modules: StatefulRolesClassMethods, StatefulRolesInstanceMethods

Constant Summary collapse

STATEFUL_ROLES_CONSTANTS_DEFINED =

sorry for the C idiom

'yup'

Class Method Summary collapse

Class Method Details

.included(recipient) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/authorization/aasm_roles.rb', line 8

def self.included( recipient )
  recipient.extend( StatefulRolesClassMethods )
  recipient.class_eval do
    include StatefulRolesInstanceMethods
    include ActiveRecord::Transitions
    
    state_machine do
    
      state :passive
      state :active #,  :enter => :do_activate
      state :suspended
      state :deleted, :enter => :do_delete
    
      event :register do
        # transitions :from => :passive, :to => :pending, :guard => Proc.new {|u| !(u.crypted_password.blank? && u.password.blank?) }
        transitions :from => :passive, :to => :active#, :guard => Proc.new {|u| !(u.crypted_password.blank? && u.password.blank?) }
      end
    
      # event :activate do
      #   transitions :from => :pending, :to => :active 
      # end
    
      event :suspend do
        # transitions :from => [:passive, :pending, :active], :to => :suspended
        transitions :from => [:passive, :active], :to => :suspended
      end
    
      event :delete do
        # transitions :from => [:passive, :pending, :active, :suspended], :to => :deleted
        transitions :from => [:passive, :active, :suspended], :to => :deleted
      end
    
      event :unsuspend do
        # transitions :from => :suspended, :to => :active,  :guard => Proc.new {|u| !u.activated_at.blank? }
        transitions :from => :suspended, :to => :active,  :guard => Proc.new {|u| !u.crypted_password.blank? }
        # transitions :from => :suspended, :to => :pending, :guard => Proc.new {|u| !u.activation_code.blank? }
        transitions :from => :suspended, :to => :passive
      end
    
    
    end
    
  end
end