Module: Request::Statemachine::ClassMethods

Included in:
TransferRequest
Defined in:
app/models/request/statemachine.rb

Instance Method Summary collapse

Instance Method Details

#destroy_aasmObject


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/request/statemachine.rb', line 18

def destroy_aasm
  # Destroy all evidence of the statemachine we've inherited!  Ugly, but it works!
  old_machine = AASM::StateMachineStore.fetch(self) && AASM::StateMachineStore.fetch(self).machine(:default)
  if old_machine
    old_machine.events.keys.each do |event|
      undef_method(event);
      undef_method(:"#{event}!");
      undef_method(:"may_#{event}?")
    end
    old_machine.states.each do |state|
      undef_method(:"#{state}?")
    end
  end
  # Wipe out the inherited state machine. Can't use unregister
  # as we still need the state machine on the parent class.
  AASM::StateMachineStore.register(self, true)
end

#redefine_aasm(options = {}, &block) ⇒ Object


13
14
15
16
# File 'app/models/request/statemachine.rb', line 13

def redefine_aasm(options = {}, &block)
  destroy_aasm
  aasm(options, &block)
end