Module: Philiprehberger::StateMachine::ClassMethods
- Defined in:
- lib/philiprehberger/state_machine.rb
Instance Method Summary collapse
-
#_sm_definition ⇒ Definition
The state machine definition.
-
#state_machine(initial:) { ... } ⇒ Object
Define a state machine on the class.
-
#to_dot(name: self.name || 'StateMachine') ⇒ String
Generate a DOT/GraphViz string for this state machine.
-
#unreachable_states ⇒ Array<Symbol>
Find states that cannot be reached from the initial state.
Instance Method Details
#_sm_definition ⇒ Definition
Returns the state machine definition.
40 41 42 |
# File 'lib/philiprehberger/state_machine.rb', line 40 def _sm_definition @_sm_definition end |
#state_machine(initial:) { ... } ⇒ Object
Define a state machine on the class.
30 31 32 33 34 35 36 37 |
# File 'lib/philiprehberger/state_machine.rb', line 30 def state_machine(initial:, &block) definition = Definition.new(initial: initial) definition.instance_eval(&block) @_sm_definition = definition InstanceMethods.define_methods(self, definition) end |
#to_dot(name: self.name || 'StateMachine') ⇒ String
Generate a DOT/GraphViz string for this state machine.
48 49 50 51 52 |
# File 'lib/philiprehberger/state_machine.rb', line 48 def to_dot(name: self.name || 'StateMachine') raise Error, 'No state machine defined' unless @_sm_definition GraphExport.to_dot(@_sm_definition, name: name) end |
#unreachable_states ⇒ Array<Symbol>
Find states that cannot be reached from the initial state.
57 58 59 60 61 |
# File 'lib/philiprehberger/state_machine.rb', line 57 def unreachable_states raise Error, 'No state machine defined' unless @_sm_definition Validation.unreachable_states(@_sm_definition) end |