has_state_machine 1.3.0 → 1.3.1
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/README.md +1 -1
- data/lib/has_state_machine/state.rb +11 -6
- data/lib/has_state_machine/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: 67cb6cdd8b2615f9ca486802de5ef3bd55d5cc3f935ec069a9c888adf509a844
|
|
4
|
+
data.tar.gz: ae0d204c60f82cab7656633e562d49b7ee0501e4b15a65c9daa3b19cb9b5e92a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a5863cd591499b89b2fbd77140b665c795bc552d686040faa7ebf3dad26f1b19ae3c4dd7f88a88e1aea31a3fb49168f35b3ff11a9d5e3294cea0fd1aa26ada26
|
|
7
|
+
data.tar.gz: 399f43970999929b7f50735479e598271d2c3d831c744cb83d12317cca01d09169535088dbdbeb8e7fd7e668d1b2a48be11528fe084802524cbe2dffa374ae6a
|
data/README.md
CHANGED
|
@@ -292,7 +292,7 @@ end
|
|
|
292
292
|
`after_transition_commit` callbacks run after the outermost database transaction commits. In detail:
|
|
293
293
|
|
|
294
294
|
- If no transaction is open when `transition_to` is called, they run immediately after the transition commits.
|
|
295
|
-
- If the transition happens inside an open transaction — an app-level `ActiveRecord::Base.transaction`, or a nested transition triggered from another state's `before_transition`/`after_transition` — they are deferred until that outermost transaction commits.
|
|
295
|
+
- If the transition happens inside an open transaction — an app-level `ActiveRecord::Base.transaction`, or a nested transition triggered from another state's `before_transition`/`after_transition` — they are deferred until that outermost transaction commits, however deeply nested, including through `requires_new` savepoints and `joinable: false` blocks.
|
|
296
296
|
- They never run if the transition fails, if `rollback_transition` is raised, or if a surrounding transaction rolls back after the transition. Multiple transitions inside one transaction each fire their callbacks after commit, in transition order.
|
|
297
297
|
|
|
298
298
|
This makes `after_transition_commit` the safe place to enqueue background jobs, call external APIs, etc.: the work only happens once the new state is actually visible to other database connections.
|
|
@@ -130,15 +130,20 @@ module HasStateMachine
|
|
|
130
130
|
true
|
|
131
131
|
end
|
|
132
132
|
|
|
133
|
-
# Use the current transaction: after_all_transactions_commit ignores our
|
|
134
|
-
# non-joinable transactions and would run callbacks before commit.
|
|
135
133
|
def enqueue_transition_commit_callbacks
|
|
136
|
-
|
|
134
|
+
after_outermost_commit { run_callbacks(:transition_commit) { true } }
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Walk up to the real COMMIT: Rails runs after_commit early under a
|
|
138
|
+
# non-joinable parent, and after_all_transactions_commit skips those.
|
|
139
|
+
def after_outermost_commit(&block)
|
|
140
|
+
transaction = object.class.connection.current_transaction
|
|
141
|
+
return yield unless transaction.open?
|
|
137
142
|
|
|
138
|
-
# Rails < 7.2 has no Transaction#after_commit
|
|
139
|
-
return
|
|
143
|
+
# Rails < 7.2 has no Transaction#after_commit.
|
|
144
|
+
return yield unless transaction.respond_to?(:after_commit)
|
|
140
145
|
|
|
141
|
-
|
|
146
|
+
transaction.after_commit { after_outermost_commit(&block) }
|
|
142
147
|
end
|
|
143
148
|
|
|
144
149
|
def rollback_transition
|