Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you model state_machine style transitions? #56

Closed
markquezada opened this issue May 25, 2014 · 7 comments
Closed

How do you model state_machine style transitions? #56

markquezada opened this issue May 25, 2014 · 7 comments

Comments

@markquezada
Copy link

Hi, I just came across Statesman and it looks awesome.

This is more of a question than a bug, but I didn't know where else to ask. I'm trying out Statesman by converting an old project that used the state_machine gem. A common pattern used with that gem is to define several transitions on an event like so:

    event :deliver do
      # The first transition that matches the state and passes its conditions
      # will be used
      transition :pending => :delivered, :if => :deliver_text_message
      transition :pending => :delivery_failed
    end

The key point being that you can define a transition for what happens if deliver_text_message fails.

I can't quite figure out how to model something like this with Statesman since all transitions are defined by their "from" and "to" states, not with an explicit "event" like in state_machine. The only thing I can think of is that you're deliberately pushing this type of functionality up the stack into a service object, or the like.

I'm curious how you're modeling something like this where state transition is dependent on say, an API's return value?

@iurimatias
Copy link
Contributor

#63

@gogiel
Copy link

gogiel commented Aug 26, 2014

#63 doesn't solve the problem. It's not possible to make two transitions from one state in a single event,. The only way now is to implement "event" method manually with branching statement. @mrappleton what do you think about adding :if statement to transition method?

@isaacseymour
Copy link
Contributor

I believe #78 would allow you to put a guard on the transition from: :pending, to: :delivered which passes only when deliver_text_message is true. Then the first acceptable transition would be performed, which I think is the desired effect?

@markquezada
Copy link
Author

@isaacseymour Yes, that's exactly what I'd hope to happen. That's the only issue keeping me from using statesman on our project right now.

@isaacseymour
Copy link
Contributor

@markquezada we've discussed adding this kind of behaviour to Statesman in the office and decided it goes against the underlying philosophy of the gem - see [this comment[(https://github.com//pull/78#issuecomment-56190184). We think this behaviour belongs in your controller, or something like a MessageDeliveryService.

@markquezada
Copy link
Author

I've added some comments directly on that pull request.

@jackfranklin
Copy link
Contributor

Most of the discussion on this is now in #78 (comment), so I'm going to close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants