Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Rob Nichols
    @reggieb
    Hi Piotr. I've a quick query regarding finite_machine and thought I'd give gitter a try to ask it.
    I have an app that manages projects through a work flow. Finite machine is working a treat to do that. However, the client has now asked for the ability to rollback to the previous state. One way to achieve that would be to build a rollback work flow, but that seems like duplicating work as it will just be a reverse of the normal work flow. Is there a finite machine function that I could use to achieve the same thing?
    Another option would be for my projects to remember their previous state and then on rollback to restore! to the previous state.
    Rob Nichols
    @reggieb
    OK - I've looked through the structure of transitions, and rollback isn't just a reversed transition, because each transition has a single end point, but can have multiple starting points - so how would rollback know which starting point to roll the system back to.
    Therefore I think the solution is have my objects remember the states they have passed through, and then make rollback restore! to a previous remembered state.
    Piotr Murach
    @piotrmurach
    Hi Rob, good to see you in new year!
    It so happens that i'm saving the previous state due to various reasons, one of the being ability to provide from and to information in callbacks. So similar to current method, you can call the previous_state to get hold of the information. This is not documented feature. Would that help?
    Piotr Murach
    @piotrmurach
    Another thing I thought of is to add history to the machine so you can rollback, let us say, 5 states back. Do you reckon there would be any need for that? I'm not sure if that should be part of the library or external/optional dependency. Any thoughts?
    Rob Nichols
    @reggieb
    Hi again. When I was looking around the available methods, I spotted previous_state, but it seem to return the first state rather than the previous state. I think the problem is that the history needs to be persisted, so that needs to be done outside of finite_machine. In the end I created a attribute on my model and made it a serialized array. Then use the transition callback to push the from state into the array. I could then add a rollback method to the model which popped out the last state, reset the model's state (which persists state), and reset the associated finite machine to same state. It works a treat.
    I can post some the code I used tomorrow when I'm back at work, if you want to see it.
    Oh! And happy new year :smile:
    Piotr Murach
    @piotrmurach
    I'd defo like to take a look, I was thinking back in the day that I could create a separate library that adds persistence to finite_machine. Then I thought against it as the thought of supporting different storages/orms brings a chill to my spine. I still think what you have there could be potentially added to the readme section or even better we could add examples folder for some real-world TM solutions:)
    Rob Nichols
    @reggieb
    @peter-murach, I think the place for "examples" is the project's github wiki page.
    Rob Nichols
    @reggieb
    This message was deleted
    Rob Nichols
    @reggieb
    Here is an example that I've created by stripping out the relevant parts from my current app: https://gist.github.com/reggieb/4f4863a3e43ff49317ab