def transition_to(path, current_state=self.current_state)
      path = path.to_s
      state = current_state || self
      exit_states = []

      # Find the nearest parent state on the path of the current state which
      # has a sub-state at the given path
      new_states = state.find_states(path)
      while(!new_states) do
        exit_states << state
        state = state.parent_state
        raise(StateNotFound, transition_error(path)) unless state
        new_states = state.find_states(path)
      end

      # The first time we enter a state, the state_manager gets entered as well
      new_states.unshift(self) unless has_state?

      # Can only transition to leaf states
      # TODO: transition to the initial_state of the state?
      raise(InvalidTransition, transition_error(path)) unless new_states.last.leaf?

      enter_states = new_states - exit_states
      exit_states = exit_states - new_states

      from_state = current_state
      # TODO: does it make more sense to throw an error instead of allowing
      # a transition to the current state?
      to_state = enter_states.last || from_state

      run_before_callbacks(from_state, to_state, current_event, enter_states, exit_states)

      # Set the state on the underlying resource
      self.current_state = to_state

      run_after_callbacks(from_state, to_state, current_event, enter_states, exit_states)
    end
def transition_to(path, current_state=self.current_state)
      path = path.to_s
      state = current_state || self
      exit_states = []

      # Find the nearest parent state on the path of the current state which
      # has a sub-state at the given path
      new_states = state.find_states(path)
      while(!new_states) do
        exit_states << state
        state = state.parent_state
        raise(StateNotFound, transition_error(path)) unless state
        new_states = state.find_states(path)
      end

      # The first time we enter a state, the state_manager gets entered as well
      new_states.unshift(self) unless has_state?

      # Can only transition to leaf states
      # TODO: transition to the initial_state of the state?
      raise(InvalidTransition, transition_error(path)) unless new_states.last.leaf?

      enter_states = new_states - exit_states
      exit_states = exit_states - new_states

      from_state = current_state
      # TODO: does it make more sense to throw an error instead of allowing
      # a transition to the current state?
      to_state = enter_states.last || from_state

      run_before_callbacks(from_state, to_state, current_event, enter_states, exit_states)

      # Set the state on the underlying resource
      self.current_state = to_state

      run_after_callbacks(from_state, to_state, current_event, enter_states, exit_states)
    end
Transitions to the state at the specified path. The path can be relative
 to any state along the current state's path.