state_machines 0.100.0 → 0.100.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b240916b3b1592fd9980f8dc7583dac5b9af93cf38c193ffb6e2427f3f15f6c0
|
4
|
+
data.tar.gz: ea38fc11bd6619335415d3a90b92f7f5909df03e5fd087aaf14716dca977d847
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80517f65fa434f346e552677e08cdd6b04e3d573eef756d058645a4d067bb1dd21331d86d657b0df429cfc3157d48cff3bfe594bb7bcb79f4a34b89cf880150c
|
7
|
+
data.tar.gz: '01874fcbb634ec7daf80bd3a5d87169644916ebb71e4bbfaaf1891ce53beac963261e2684df288b8aaedf057dae66e64f3167bdd6a676b095562096edbf25c42'
|
@@ -33,6 +33,12 @@ module StateMachines
|
|
33
33
|
def matches_ancestors?(ancestors)
|
34
34
|
(ancestors & matching_ancestors).any?
|
35
35
|
end
|
36
|
+
|
37
|
+
# Additional options that this integration adds to the state machine.
|
38
|
+
# Integrations can override this method to specify additional valid options.
|
39
|
+
def integration_options
|
40
|
+
[]
|
41
|
+
end
|
36
42
|
end
|
37
43
|
|
38
44
|
def self.included(base) # :nodoc:
|
@@ -6,14 +6,18 @@ module StateMachines
|
|
6
6
|
# Initializes a new state machine with the given configuration.
|
7
7
|
def initialize(owner_class, *args, &)
|
8
8
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
9
|
-
|
10
|
-
|
9
|
+
|
11
10
|
# Find an integration that matches this machine's owner class
|
12
11
|
@integration = if options.include?(:integration)
|
13
12
|
options[:integration] && StateMachines::Integrations.find_by_name(options[:integration])
|
14
13
|
else
|
15
14
|
StateMachines::Integrations.match(owner_class)
|
16
15
|
end
|
16
|
+
|
17
|
+
# Validate options including integration-specific options
|
18
|
+
valid_keys = [:attribute, :initial, :initialize, :action, :plural, :namespace, :integration, :messages, :use_transactions, :async]
|
19
|
+
valid_keys += @integration.integration_options if @integration
|
20
|
+
StateMachines::OptionsValidator.assert_valid_keys!(options, valid_keys)
|
17
21
|
|
18
22
|
if @integration
|
19
23
|
extend @integration
|
@@ -1,6 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module StateMachines
|
4
|
+
# Module to extend Fiber instances for pausable state tracking
|
5
|
+
module PausableFiber
|
6
|
+
attr_accessor :state_machine_fiber_pausable
|
7
|
+
end
|
8
|
+
|
4
9
|
# A transition represents a state change for a specific attribute.
|
5
10
|
#
|
6
11
|
# Transitions consist of:
|
@@ -397,7 +402,8 @@ module StateMachines
|
|
397
402
|
# Create a new fiber to run the block
|
398
403
|
fiber = Fiber.new do
|
399
404
|
# Mark that we're inside a pausable fiber
|
400
|
-
|
405
|
+
Fiber.current.extend(StateMachines::PausableFiber)
|
406
|
+
Fiber.current.state_machine_fiber_pausable = true
|
401
407
|
begin
|
402
408
|
halted = !catch(:halt) do
|
403
409
|
yield
|
@@ -409,7 +415,7 @@ module StateMachines
|
|
409
415
|
[:error, e]
|
410
416
|
ensure
|
411
417
|
# Clean up the flag
|
412
|
-
|
418
|
+
Fiber.current.state_machine_fiber_pausable = false
|
413
419
|
end
|
414
420
|
end
|
415
421
|
|
@@ -448,8 +454,9 @@ module StateMachines
|
|
448
454
|
return if @resuming
|
449
455
|
|
450
456
|
# Only yield if we're actually inside a fiber created by pausable
|
451
|
-
# We use a
|
452
|
-
|
457
|
+
# We use a module extension to track this
|
458
|
+
current_fiber = Fiber.current
|
459
|
+
return unless current_fiber.respond_to?(:state_machine_fiber_pausable) && current_fiber.state_machine_fiber_pausable
|
453
460
|
|
454
461
|
Fiber.yield
|
455
462
|
|