Raise an exception if the state is not found [Joel Westerberg]
This commit is contained in:
parent
173fa5723b
commit
7105344210
|
@ -10,6 +10,9 @@ module AASM
|
||||||
|
|
||||||
class InvalidTransition < RuntimeError
|
class InvalidTransition < RuntimeError
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class UndefinedState < RuntimeError
|
||||||
|
end
|
||||||
|
|
||||||
def self.included(base) #:nodoc:
|
def self.included(base) #:nodoc:
|
||||||
# TODO - need to ensure that a machine is being created because
|
# TODO - need to ensure that a machine is being created because
|
||||||
|
@ -117,7 +120,9 @@ module AASM
|
||||||
end
|
end
|
||||||
|
|
||||||
def aasm_state_object_for_state(name)
|
def aasm_state_object_for_state(name)
|
||||||
self.class.aasm_states.find {|s| s == name}
|
obj = self.class.aasm_states.find {|s| s == name}
|
||||||
|
rasie AASM::UndefinedState, "State :#{name} doesn't exist" if obj.nil?
|
||||||
|
obj
|
||||||
end
|
end
|
||||||
|
|
||||||
def aasm_fire_event(name, persist, *args)
|
def aasm_fire_event(name, persist, *args)
|
||||||
|
|
Loading…
Reference in New Issue