lib/aasm.rb in runcoderun-aasm-2.0.2.4 vs lib/aasm.rb in runcoderun-aasm-2.0.5

- old
+ new

@@ -3,15 +3,18 @@ require File.join(File.dirname(__FILE__), 'state_machine') require File.join(File.dirname(__FILE__), 'persistence') module AASM def self.Version - '2.0.2.4' + '2.0.5' end class InvalidTransition < RuntimeError end + + class UndefinedState < RuntimeError + end def self.included(base) #:nodoc: # TODO - need to ensure that a machine is being created because # AASM was either included or arrived at via inheritance. It # cannot be both. @@ -20,11 +23,11 @@ AASM::StateMachine[base] = AASM::StateMachine.new('') end module ClassMethods def inherited(klass) - AASM::StateMachine[klass] = AASM::StateMachine[self].dup + AASM::StateMachine[klass] = AASM::StateMachine[self].clone super end def aasm_initial_state(set_state=nil) if set_state @@ -115,10 +118,12 @@ end @aasm_current_state = state end def aasm_state_object_for_state(name) - self.class.aasm_states.find {|s| s == name} + obj = self.class.aasm_states.find {|s| s == name} + raise AASM::UndefinedState, "State :#{name} doesn't exist" if obj.nil? + obj end def aasm_fire_event(name, persist, *args) aasm_state_object_for_state(aasm_current_state).call_action(:exit, self)