sequel-state-machine 1.2.2 → 1.3.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/sequel/plugins/state_machine.rb +18 -8
- data/lib/state_machines/sequel/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66c4bb795fc20985f7b8c94a41d85020f0a4cb74974f36df8434aa3f46ee6ebb
|
4
|
+
data.tar.gz: 2725ec4bc5941b310923dfb44b0397cba560af00022f85309b9fea6a5015599f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c346b5561103439e1b28490c9e86d11b59663d16693490ae5e08f2895b82fd62af22c6caf383ad19038769f5b881506eaf4e3c6a6a8fcd9ec47c56a89e71947
|
7
|
+
data.tar.gz: 8241f9061b035a9d17b025328e5639f50bb596462b3628e59b198c4bd32f188693339a307380b20a119c540a480389ead36e8f51dfb95a4bcb855471ac80e231
|
@@ -83,6 +83,16 @@ module Sequel
|
|
83
83
|
return alog
|
84
84
|
end
|
85
85
|
|
86
|
+
# Commit pending changes to the audit log.
|
87
|
+
# This involves either:
|
88
|
+
# - Updating the last audit log step, if it matches our current criteria (event, from state, to state),
|
89
|
+
# - or creating a new audit log entry.
|
90
|
+
# This ensures that we have the following behavior:
|
91
|
+
# - Failed transitions - ie where from and to state are the same - do not add multiple audit log steps.
|
92
|
+
# Only the latest failed transition is recorded.
|
93
|
+
# - Successful transitions are always recorded. If we transition, a->b->c,
|
94
|
+
# and then reset the state machine to 'a' and transition a->b->c again,
|
95
|
+
# we'd end up with 5 transitions (a->b->c->a->b->c).
|
86
96
|
def commit_audit_log(transition)
|
87
97
|
machine = self.class.state_machines.length > 1 ? transition.machine.name : nil
|
88
98
|
StateMachines::Sequel.log(
|
@@ -90,14 +100,14 @@ module Sequel
|
|
90
100
|
)
|
91
101
|
current = self.current_audit_log(machine: machine)
|
92
102
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
if
|
99
|
-
StateMachines::Sequel.log(self, :debug, "updating_audit_log", {audit_log_id:
|
100
|
-
|
103
|
+
last_log = self.audit_logs.last
|
104
|
+
can_update_last = last_log &&
|
105
|
+
last_log.sequel_state_machine_get(:event) == transition.event.to_s &&
|
106
|
+
last_log.sequel_state_machine_get(:from_state) == transition.from &&
|
107
|
+
last_log.sequel_state_machine_get(:to_state) == transition.to
|
108
|
+
if can_update_last
|
109
|
+
StateMachines::Sequel.log(self, :debug, "updating_audit_log", {audit_log_id: last_log.id})
|
110
|
+
last_log.update(**last_log.sequel_state_machine_map_columns(
|
101
111
|
at: Time.now,
|
102
112
|
actor: StateMachines::Sequel.current_actor,
|
103
113
|
messages: current.messages,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel-state-machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lithic Tech
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|