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

Multiple state_machines... #50

Closed
dlepage opened this issue May 16, 2012 · 5 comments
Closed

Multiple state_machines... #50

dlepage opened this issue May 16, 2012 · 5 comments

Comments

@dlepage
Copy link

dlepage commented May 16, 2012

Is it possible to have more than one state_machine in a model.

How to setup (state column name, fire évents from this second state_machine ?)

Many thanks !

@troessner
Copy link
Owner

Well, in theory it should be possible, however I found out that this doesn't work right now unfortunately.
If I find the time, I'll fix that - of course pull requests are welcome..:-)
To be honest this isn't very high on my priority list, because whenever I had the need for two state machines, I basically wanted two different models. However I don't deny that there might be use cases where multiple state machines make sense, I just haven't encountered one.
As far as I can see even naming a state machine with

state_machine :foo do

breaks the functionality. But then again, naming a state machine only makes sense if we have more than one (otherwise it's just default), so this is all more or less the same issue.

I am thinking of something like this (This won't work right now):

state_machine do # name will be `default`
  ...
end

state_machine :foo
  ...
end

where you can switch like that

my_model.switch_state_machine :foo

If you need that badly, you'll have to come up with a pull request I'm afraid..:-)

@troessner
Copy link
Owner

@dlepage Oh, and what's your use case for having multiple state machines for one model?

@dlepage
Copy link
Author

dlepage commented May 18, 2012

Sure ! :) First of all, most of the time it's better to split a model into simple models... but sometime, it's overkill.

We can imagine a model that you have two(or more) points of view... eg. :

  • Human... mental_state, physical_state...
  • Order : shipping(processing) state, invoice state (NOTE: I know, an Invoice model can do the trick but adding a model just to manage a state seems overkill (and more left joins is not really better...)).

On 2012-05-18, at 07:16, Timo Rößner wrote:

@dlepage Oh, and what's your use case for having multiple state machines for one model?


Reply to this email directly or view it on GitHub:
#50 (comment)

@troessner
Copy link
Owner

I see your reasoning. However, I am not convinced - "Human being" would be a "human" object composed of "body" and "spirit" for me...:-)
I am closing this issue.

@dlepage
Copy link
Author

dlepage commented May 22, 2012

Please add "this gem is limited to one state machine for each model.

Envoyé de mon iPhone

Le 2012-05-21 à 18:41, "Timo Rößner"
reply@reply.github.com
a écrit :

I see your reasoning. However, I am not convinced - "Human being" would be a "human" object composed of "body" and "spirit" for me...:-)
I am closing this issue.


Reply to this email directly or view it on GitHub:
#50 (comment)

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

2 participants