sequel-state-machine 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94b067e5d260a2c467a1f1b8b4ec206054c29ab7fc54a86d2b5a89cc7a6620b1
4
- data.tar.gz: aea214e6ab04cb78cffc4d580ae1de70011d9f0052562aa3649c217447d9ae0b
3
+ metadata.gz: 66c4bb795fc20985f7b8c94a41d85020f0a4cb74974f36df8434aa3f46ee6ebb
4
+ data.tar.gz: 2725ec4bc5941b310923dfb44b0397cba560af00022f85309b9fea6a5015599f
5
5
  SHA512:
6
- metadata.gz: 9e8ee131d5e6da8495c7fb998ca81fbfdb43f8a6b7feb52bb919011e51d2d79c38ca190ba12fbf3d866d4aaf0484ae5db7601f903aec162736abdea1f6f05187
7
- data.tar.gz: de91701d5ae07856d516c64963cfb988b12333c1e2bcc929f29d37cabad1cc779929cc9d07216fd6af6afb8780e19a2714b40dbb497918b32ca0e1971ce0cd64
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
- last_saved = self.audit_logs.find do |a|
94
- a.sequel_state_machine_get(:event) == transition.event.to_s &&
95
- a.sequel_state_machine_get(:from_state) == transition.from &&
96
- a.sequel_state_machine_get(:to_state) == transition.to
97
- end
98
- if last_saved
99
- StateMachines::Sequel.log(self, :debug, "updating_audit_log", {audit_log_id: last_saved.id})
100
- last_saved.update(**last_saved.sequel_state_machine_map_columns(
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,
@@ -2,6 +2,6 @@
2
2
 
3
3
  module StateMachines
4
4
  module Sequel
5
- VERSION = "1.2.2"
5
+ VERSION = "1.3.0"
6
6
  end
7
7
  end
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.2.2
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-06-25 00:00:00.000000000 Z
11
+ date: 2022-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec