alexpeachey / end_state

A State Machine implementation
MIT License
9 stars 5 forks source link

SOLIDify Transition #18

Closed charlierudolph closed 10 years ago

charlierudolph commented 10 years ago

I'd like to do a number of things around Transition.

I was about to create a PR with the following

In doing so I came up with another change I would like to implement

def transition(state, params = {}, mode = self.class.mode)
  @failure_messages = []
  @success_messages = []
  previous_state = self.state ? self.state.to_sym : self.state
  state = state.to_sym
  mode = __sm_actual_mode(mode)
  transition_configuration = __sm_transition_configuration_for(previous_state, state)
  Transition.new(self, previous_state, state, transition_configuration, mode).call  
end

I think this will help move a lot of transition logic out of the state machine and into its own class. Didn't create a PR for the current work as if you agree, TransitionConfiguration becomes quite different.

alexpeachey commented 10 years ago

Thanks @charlierudolph, yes please move forward with this. It's been on our list for a while to make StateMachine know a lot less about Transitions. Pretty much all of the relevant logic in the gem in encapsulated in the StateMachine class.

I like the idea of a TransitionConfiguration class that has the relevant info about the guards, concluders, etc. And then a Transition class that would take over a lot of the logic wrapped up inside StateMachine.

Ideally you can do this as a pure refactor and not have any changes to the API. If you do find you need to change the API, please call it out clearly.