Transitions¶
The smallest atom of edgy.workflow
is a Transition
, which basically is a regular python
callable with additional metadata to make the system aware of when it can be applied.
-
class
edgy.workflow.
Transition
(handler=None, name=None, source=None, target=None)[source]¶ Defines when and how to go from one state to another, eventually applying a user-defined side-effect while being applied.
Example:
>>> t = Transition(name='sleep', source='awake', target='asleep') >>> class Person(object): ... state = 'awake' >>> me = Person() >>> t(me) >>> me.state 'asleep'
This class can also be used as a decorator:
>>> @Transition(source='asleep', target='awake') >>> def wakeup(self, subject): ... print('HEY!') >>> wakeup(me) >>> me.state 'awake'
A special wildcard source can make transitions work from any state. Just specify “*” as a transition source and you’ll be able to transition from any state.