fire_state_event!
Opened this issue · 3 comments
I can't find the bang version of fire_state_event
(throw error instead of returning false). What is the best way to add this feature?
We've been using the following pattern:
# for state machine on attribute 'status' and some event_name
my_model.update_attributes!(status_event: event_name)
This raises an exception, essentially triggering the bang version of the event. Apparently this may be part of the ActiveRecord extension, though: #36 (very dated, but result of a quick search)
Hope this helps.
Still looking for the implementation, but there's some documentation here: https://github.com/pluginaweek/state_machine#explicit-vs-implicit-event-transitions
Found the implementation of implicit / attribute-based state transitions here:
state_machines/lib/state_machines/machine.rb
Line 1051 in c94d690
It looks like there are some caveats with implicit transitions documented elsewhere:
state_machines/lib/state_machines/machine.rb
Line 1204 in c94d690
I didn't see any support for passing arguments (ex: an attribute like state_event_arguments
), and adding this as an additional attribute seems messy.
Therefore I would also be in favor of defining a .fire!()
method, possibly via a special argument to .fire()
, and rewriting Event.add_actions
to leverage that instead:
state_machines/lib/state_machines/event.rb
Line 224 in a8e18f6