Method: StateMachine::StateCollection#by_priority
- Defined in:
- lib/state_machine/state_collection.rb
#by_priority ⇒ Object
Gets the order in which states should be displayed based on where they were first referenced. This will order states in the following priority:
-
Initial state
-
Event transitions (:from, :except_from, :to, :except_to options)
-
States with behaviors
-
States referenced via
stateorother_states -
States referenced in callbacks
This order will determine how the GraphViz visualizations are rendered.
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/state_machine/state_collection.rb', line 93 def by_priority order = select {|state| state.initial}.map {|state| state.name} machine.events.each {|event| order += event.known_states} order += select {|state| state.methods.any?}.map {|state| state.name} order += keys(:name) - machine.callbacks.values.flatten.map {|callback| callback.known_states}.flatten order += keys(:name) order.uniq! order.map! {|name| self[name]} order end |