README.md in end_state-0.3.2 vs README.md in end_state-0.4.0

- old
+ new

@@ -60,10 +60,21 @@ machine.state # => :a machine.go! # => :true machine.state # => :b ``` +## Initial State + +If you wrap an object that currently has `nil` as the state, the state will be set to `:__nil__`. +You can change this using the `set_initial_state` method. + +```ruby +class Machine < EndState::StateMachine + set_initial_state :first +end +``` + ## Guards Guards can be created by subclassing `EndState::Guard`. Your class will be provided access to: * `object` - The wrapped object. @@ -221,32 +232,40 @@ ## State storage You may want to use an attribute other than `state` to track the state of the machine. -``` +```ruby class Machine < EndState::StateMachine state_attribute :status end ``` Depending on how you persist the `state` (if at all) you may want what is stored in `state` to be a string instead of a symbol. You can tell the machine this preference. -``` +```ruby class Machine < EndState::StateMachine store_states_as_strings! end ``` ## Exceptions for failing Transitions -By default `transition` will only raise an exception, `EndState::UnknownState`, if called with a state that doesn't exist. +By default `transition` will only raise an error, `EndState::UnknownState`, if called with a state that doesn't exist. All other failures, such as missing transition, guard failure, or finalizer failure will silently just return `false` and not transition to the new state. You also have the option to use `transition!` which will instead raise an error for failures. If your guards and/or finalizers add to the `failure_messages` array then they will be included in the error message. + +Additionally, if you would like to treat all transitions as hard and raise an error you can set that in the machine definition. + +```ruby +class Machine < EndState::StateMachine + treat_all_transitions_as_hard! +end +``` ## Graphing If you install `GraphViz` and the gem `ruby-graphviz` you can create images representing your state machines.