Module: WizardMachine::ClassMethods

Defined in:
lib/wizard_machine.rb

Instance Method Summary collapse

Instance Method Details

#all_state_namesObject



37
38
39
# File 'lib/wizard_machine.rb', line 37

def all_state_names
  @all_state_names ||= self.aasm_states.collect(&:name)
end

#setup_wizard_events!Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/wizard_machine.rb', line 49

def setup_wizard_events!
  aasm_state :wizard_complete
  
  aasm_event :created do
    transitions :to => WizardMachine.__wizard_machine_processing_class.wizard_state_names.first, :from => [:new]
  end
  aasm_event :wizard_complete do
    transitions :to => :wizard_complete, :from => WizardMachine.__wizard_machine_processing_class.all_state_names
  end
  wizard_state_names.each do |state|
    aasm_event state do
      transitions :to => state, :from => WizardMachine.__wizard_machine_processing_class.all_state_names
    end
  end
  WizardMachine.__wizard_machine_processing_class = nil
end

#wizard_state(*args) ⇒ Object



27
28
29
30
31
# File 'lib/wizard_machine.rb', line 27

def wizard_state(*args)
  @all_state_names = nil
  @wizard_state_names = nil
  aasm_state(*args)
end

#wizard_state_is(state) ⇒ Object



33
34
35
# File 'lib/wizard_machine.rb', line 33

def wizard_state_is(state)
  Proc.new { || .wizard_state == state }
end

#wizard_state_namesObject



41
42
43
# File 'lib/wizard_machine.rb', line 41

def wizard_state_names
  @wizard_state_names ||= all_state_names - [:new]
end

#wizard_total_stepsObject



45
46
47
# File 'lib/wizard_machine.rb', line 45

def wizard_total_steps
  wizard_state_names.size-1
end