flow_state 0.1.5 → 0.1.6
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/flow_state/base.rb +9 -4
- data/lib/flow_state/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: 957aaac94425fb52e1566d1e89c8084c01f021b5fefff56a9899ee69d06ff8fc
|
4
|
+
data.tar.gz: 8b5949635034e88ed15fe31ae1c3c4e6cd6343785a823c9251e2c88911d7520a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8798ed03aa73c9120d27641692a0165d7a82c4e8d9b4531b74c1483ab87fb5e896fa7e323611cce81f8d120030bc5c94df79887337befdb7208dcde8190e4d09
|
7
|
+
data.tar.gz: 499e2d7f6da573ce36e95e491275d42e2846affe7d8def6c02c9db5013417fc495b639eb223bd96a789f9e92b6af4a152a0d8281038b34719fca1490e5663518
|
data/lib/flow_state/base.rb
CHANGED
@@ -61,7 +61,7 @@ module FlowState
|
|
61
61
|
validates :current_state, presence: true
|
62
62
|
validate :validate_payload
|
63
63
|
|
64
|
-
after_initialize
|
64
|
+
after_initialize :assign_initial_state, if: :new_record?
|
65
65
|
|
66
66
|
def transition!(from:, to:, guard: nil, persists: nil, after_transition: nil, &block)
|
67
67
|
setup_transition!(from, to, guard, persists, &block)
|
@@ -75,6 +75,10 @@ module FlowState
|
|
75
75
|
|
76
76
|
private
|
77
77
|
|
78
|
+
def assign_initial_state
|
79
|
+
self.current_state ||= resolve_initial_state
|
80
|
+
end
|
81
|
+
|
78
82
|
def setup_transition!(from, to, guard, persists, &block)
|
79
83
|
@from_states = Array(from).map(&:to_sym)
|
80
84
|
@to_state = to.to_sym
|
@@ -85,9 +89,10 @@ module FlowState
|
|
85
89
|
end
|
86
90
|
|
87
91
|
def perform_transition!(to, persists) # rubocop:disable Metrics/MethodLength
|
88
|
-
|
89
|
-
|
90
|
-
|
92
|
+
transaction do
|
93
|
+
save! if changed?
|
94
|
+
with_lock do
|
95
|
+
ensure_valid_from_state!(@from_states, to)
|
91
96
|
@tr = flow_transitions.create!(
|
92
97
|
transitioned_from: current_state,
|
93
98
|
transitioned_to: to
|
data/lib/flow_state/version.rb
CHANGED