state_machines 0.200.0 → 0.201.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/state_machines/transition.rb +13 -0
- data/lib/state_machines/transition_collection.rb +27 -0
- data/lib/state_machines/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fcd3d5e6fc0f3982c8ddabc40480b43375d6e323957dd392ca4b3cc10f9c0f40
|
|
4
|
+
data.tar.gz: 89556aa64bb82045527f260098dd801acce298be5ad873ed7f250805b7839c87
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d44ae6b303dc577db3ed8aa70d7132521b8be94c3651fa9afe886e90c7561ebea686d1c743adc9464d08bd01d2903a4e75eabf7aa567abacab81d0b1c889fea4
|
|
7
|
+
data.tar.gz: b04cbf3f1cb69b943fdf19aa91f37b3376f976c4ed28bd08ab4aed18af6473b3508c05fe52317f10f2627660a67a3e8c3e8481a520ba2985a5c7c37316499e51
|
|
@@ -346,6 +346,19 @@ module StateMachines
|
|
|
346
346
|
!halted
|
|
347
347
|
end
|
|
348
348
|
|
|
349
|
+
# Completes a transition whose before phase has already run by executing
|
|
350
|
+
# its after callbacks, resuming any paused around callbacks first. Used
|
|
351
|
+
# to finish transitions that were stored for deferred completion (e.g.
|
|
352
|
+
# generated mid-action from an event attribute) once their action has
|
|
353
|
+
# succeeded.
|
|
354
|
+
def complete_deferred_after_callbacks
|
|
355
|
+
if paused?
|
|
356
|
+
run_callbacks(after: true)
|
|
357
|
+
else
|
|
358
|
+
after
|
|
359
|
+
end
|
|
360
|
+
end
|
|
361
|
+
|
|
349
362
|
private
|
|
350
363
|
|
|
351
364
|
# Runs a block that may get paused. If the block doesn't pause, then
|
|
@@ -257,11 +257,38 @@ module StateMachines
|
|
|
257
257
|
object.instance_variable_set(:@_state_machine_event_transitions, transitions_by_machine)
|
|
258
258
|
end
|
|
259
259
|
end
|
|
260
|
+
|
|
261
|
+
# Complete any transitions that other machines generated mid-action
|
|
262
|
+
# (e.g. an event attribute set in a before callback and picked up by
|
|
263
|
+
# the validation cycle) so their after callbacks run in this same
|
|
264
|
+
# action cycle instead of leaking into the next one (issue #91)
|
|
265
|
+
complete_nested_transitions unless skip_after
|
|
260
266
|
else
|
|
261
267
|
super
|
|
262
268
|
end
|
|
263
269
|
end
|
|
264
270
|
|
|
271
|
+
# Completes transitions that were stored for deferred completion by
|
|
272
|
+
# machines outside this collection while the action was running. Their
|
|
273
|
+
# before callbacks and state persistence already happened mid-action;
|
|
274
|
+
# only their after callbacks remain. Clears the stored references so
|
|
275
|
+
# they cannot leak into a later action cycle with stale data (issue #91).
|
|
276
|
+
def complete_nested_transitions
|
|
277
|
+
return if empty? || !success?
|
|
278
|
+
|
|
279
|
+
pending = object.instance_variable_get(:@_state_machine_event_transitions)
|
|
280
|
+
return unless pending
|
|
281
|
+
|
|
282
|
+
machines = map(&:machine)
|
|
283
|
+
pending.each_value do |transition|
|
|
284
|
+
next if machines.include?(transition.machine)
|
|
285
|
+
|
|
286
|
+
transition.machine.write(object, :event_transition, nil)
|
|
287
|
+
transition.complete_deferred_after_callbacks
|
|
288
|
+
end
|
|
289
|
+
object.instance_variable_set(:@_state_machine_event_transitions, nil)
|
|
290
|
+
end
|
|
291
|
+
|
|
265
292
|
# Tracks that before callbacks have now completed
|
|
266
293
|
def persist
|
|
267
294
|
@before_run = true
|