You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are situations where I want to guard a transition on an action that isn't idempotent, for example, processing a payment through Stripe. I want to make sure this succeeds before proceeding with the transition, but since it shouldn't be called multiple times, I don't want to trigger it when I run may_x?. Here's a simple example of an event:
event:depositdotransitionsfrom: :pending,to: :depositeddoguarddo
!project.inactive?# check every time I call may_deposit?charge_stripe# definitely don't do this when I call may_deposit?endendend
I suppose I could move charge_stripe to a before callback, but there doesn't seem to be a straightforward way to stop the transition other than raising an exception, which feels like the anti-pattern of using exceptions for flow control. I'd rather just have a way to add a guard that still fails the transition when it returns false, but doesn't run when may_deposit? is called, if that makes sense. Or maybe I'm thinking about this the wrong way ... hence I want to open a discussion about it.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
There are situations where I want to guard a transition on an action that isn't idempotent, for example, processing a payment through Stripe. I want to make sure this succeeds before proceeding with the transition, but since it shouldn't be called multiple times, I don't want to trigger it when I run
may_x?
. Here's a simple example of an event:I suppose I could move
charge_stripe
to abefore
callback, but there doesn't seem to be a straightforward way to stop the transition other than raising an exception, which feels like the anti-pattern of using exceptions for flow control. I'd rather just have a way to add a guard that still fails the transition when it returnsfalse
, but doesn't run whenmay_deposit?
is called, if that makes sense. Or maybe I'm thinking about this the wrong way ... hence I want to open a discussion about it.Beta Was this translation helpful? Give feedback.
All reactions