def by_priority
      order = select { |state| state.initial }.map { |state| state.name }

      machine.events.each { |event| order += event.known_states }
      order += select { |state| state.context_methods.any? }.map { |state| state.name }
      order += keys(:name) - machine.callbacks.values.flatten.flat_map(&:known_states)
      order += keys(:name)

      order.uniq!
      order.map! { |name| self[name] }
      order
    end
def by_priority
      order = select { |state| state.initial }.map { |state| state.name }

      machine.events.each { |event| order += event.known_states }
      order += select { |state| state.context_methods.any? }.map { |state| state.name }
      order += keys(:name) - machine.callbacks.values.flatten.flat_map(&:known_states)
      order += keys(:name)

      order.uniq!
      order.map! { |name| self[name] }
      order
    end
Gets the order in which states should be displayed based on where they
 were first referenced.  This will order states in the following priority:

 1. Initial state
 2. Event transitions (:from, :except_from, :to, :except_to options)
 3. States with behaviors
 4. States referenced via +state+ or +other_states+
 5. States referenced in callbacks

 This order will determine how the GraphViz visualizations are rendered.