Given
class Robot
include Stateflow
stateflow do
state :red, :green
end
end
robot = Robot.new
def robot.load_from_persistence
:some_invalid_state
end
> robot.green?
NoMethodError: undefined method `name' for nil:NilClass
from .../stateflow-0.4.2/lib/stateflow.rb:25:in `new?'
The error isn't immediately obvious to the user/developer.
Possible solutions:
- Revert to initial state if the persisted state is invalid
- Raise a specific exception in
current_state specifically informing the user of the invalid state
Let me know what direction you want to go with this and I'll submit a patch.