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

Generic guards #267

Open
sporto opened this issue Jul 9, 2013 · 5 comments
Open

Generic guards #267

sporto opened this issue Jul 9, 2013 · 5 comments

Comments

@sporto
Copy link

sporto commented Jul 9, 2013

At the moment I am doing something like this:

event :fulfill do
    transition [:new, :paid] => :fulfilled, :if => :can_transition?
end

event :pay do
    transition [:new, :fulfilled] => :paid, :if => :can_transition?
end

event :close do
    transition [:fulfilled, :paid] => :closed, :if => :can_transition?
end

:if => :can_transition? is repeated in every transition declaration which make the code harder to maintain.

Maybe there is a way already that I don't know of but it would be really nice if there was a way of defining generic guards, instead of this repetition.

Similar to this request
https://groups.google.com/forum/#!searchin/pluginaweek-talk/condition/pluginaweek-talk/KwE8g1OKXZg/70driFcCLG8J

@the8472
Copy link

the8472 commented Jul 9, 2013

If you don't need the fluffy can_fulfill? etc. instance methods you could just write a before_transition any => all handler that returns false if the condition is not fulfilled.

@sporto
Copy link
Author

sporto commented Jul 9, 2013

@the8472 thanks, but this doesn't seem to work, I tried returning false in a before_transition filter but the transition still happens. It seems like before_transition has no relevance to wherever the transition should proceed.

@the8472
Copy link

the8472 commented Jul 9, 2013

I thought returning false does work. But the documentation says throw :halt, so try that

@the8472
Copy link

the8472 commented Jul 9, 2013

Ah, it depends on the integration, default is the throw, but you can configure another one, such as the AR-integration does: http://rdoc.info/github/pluginaweek/state_machine/master/StateMachine/Callback:terminator

@sporto
Copy link
Author

sporto commented Jul 9, 2013

@the8472, thanks throw :halt works. Still it would be nice to have something that works with the predicate methods, .can_pay?

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