README.md in end_state-0.0.2 vs README.md in end_state-0.1.0
- old
+ new
@@ -27,11 +27,11 @@
Create a state machine by subclassing `EndState::StateMachine`.
```ruby
class Machine < EndState::StateMachine
- transition a: :b
+ transition a: :b, as: :go
transition b: :c
transition [:b, :c] => :a
end
```
@@ -56,19 +56,21 @@
machine.can_transition? :b # => false
machine.can_transition? :a # => true
machine.b! # => false
machine.a! # => true
machine.state # => :a
+machine.go! # => :true
+machine.state # => :b
```
## Guards
Guards can be created by subclassing `EndState::Guard`. Your class will be provided access to:
* `object` - The wrapped object.
* `state` - The desired state.
-* `params` - A hash of params as set in the transition definition.
+* `params` - A hash of params passed when calling transition on the machine.
Your class should implement the `will_allow?` method which must return true or false.
Optionally you can implement the `passed` and/or `failed` methods which will be called after the guard passes or fails.
These will only be called during the check performed during the transition and will not be fired when asking `can_transition?`.
@@ -93,32 +95,32 @@
```ruby
class Machine < EndState::StateMachine
transition a: :b do |t|
t.guard EasyGuard
- t.guard SomeOtherGuard, option1: 'Some Option', option2: 'Some Other Option'
+ t.guard SomeOtherGuard
end
end
```
## Finalizers
Finalizers can be created by subclassing `EndState::Finalizer`. Your class will be provided access to:
* `object` - The wrapped object that has been transitioned.
* `state` - The previous state.
-* `params` - A hash of params as set in the transition definition.
+* `params` - A hash of params passed when calling transition on the machine.
Your class should implement the `call` method which should return true or false as to whether it was successful or not.
If your finalizer returns false, the transition will be "rolled back" and the failing transition, as well as all previous transitions
will be rolled back. The roll back is performed by calling `rollback` on the finalizer. During the roll back the finalizer will be
set up a little differently and you have access to:
* `object` - The wrapped object that has been rolled back.
* `state` - The attempted desired state.
-* `params` - A hash of params as set in the transition definition.
+* `params` - A hash of params passed when calling transition on the machine.
The wrapped object has an array `failure_messages` available for tracking reasons for invalid transitions. You may shovel
a reason (string) into this if you want to provide information on why your finalizer failed.
```ruby
@@ -137,10 +139,10 @@
A finalizer can be added to the transition definition:
```ruby
class Machine < EndState::StateMachine
transition a: :b do |t|
- t.finalizer WrapUp, option1: 'Some Option', option2: 'Some Other Option'
+ t.finalizer WrapUp
end
end
```
Since it is a common use case, a finalizer is included which will call `save` on the wrapped object if it responds to `save`.