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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10897c2b3fdaea1f4728eb063c09f7996c6164f938d814dc486c746c4e91c081
4
- data.tar.gz: e7e89af7bfa089d2f1a7c7324f028223e530231e808e34398a2665c11992c168
3
+ metadata.gz: fcd3d5e6fc0f3982c8ddabc40480b43375d6e323957dd392ca4b3cc10f9c0f40
4
+ data.tar.gz: 89556aa64bb82045527f260098dd801acce298be5ad873ed7f250805b7839c87
5
5
  SHA512:
6
- metadata.gz: cb901d7e14ae688dbfec57c312a6edc338156dc0b239a9f56f6898443bbb3ed33e1aad85a260b5ab6c6aa21f3513fdac1e19f24b09418d8994be6f6f80a50a41
7
- data.tar.gz: ca11e59b75a28e0c3a9f27fae6a9ac194082a9a1a034d1160050f21c8645f69111e6179e64c5d0048143f5d095f789207372c9d2ef3b3d2a0a07e10cd154438d
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StateMachines
4
- VERSION = '0.200.0'
4
+ VERSION = '0.201.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_machines
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.200.0
4
+ version: 0.201.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih