statesman-multi_state 0.2.3 → 0.2.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3da92d3ccded26da494e323939fcb7f52e5deeeaf12890cc94fe9f0b671bcb0e
|
4
|
+
data.tar.gz: ec4878bd26d26bca13065957e1fae77557f723ee76f8dce958e36bebd0f3ecb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc7fa159bb3698b7c249851fbef0e570a8451013921fee18e14f3260cd081eb5e92bd5b65a71428640dc9cf4766322cb9202bbf86256758ba6453b89669436db
|
7
|
+
data.tar.gz: 207d514cd1930c64f21a36519e436b099bbd430536e8a8a45f4952da578bec27391f0a5f9df6adf6fb923174e52f0fe275918c78cd7354ee6a2ac08c11752e53
|
@@ -11,7 +11,7 @@ module Statesman
|
|
11
11
|
class_methods do
|
12
12
|
def has_one_state_machine(field_name, state_machine_klass:, transition_klass:,
|
13
13
|
transition_name: transition_klass.to_s.demodulize.underscore.pluralize.to_sym, virtual_attribute_name: "#{field_name}_state_form",
|
14
|
-
transition_foreign_key: nil)
|
14
|
+
transition_foreign_key: nil, initial_transition: true)
|
15
15
|
state_machine_name = "#{field_name}_state_machine"
|
16
16
|
|
17
17
|
# To handle STI, this needs to be done to get the base klass
|
@@ -39,13 +39,21 @@ module Statesman
|
|
39
39
|
|
40
40
|
def #{state_machine_name}
|
41
41
|
key = "@#{state_machine_name}"
|
42
|
-
return instance_variable_get(key) if instance_variable_defined?(key)
|
42
|
+
return instance_variable_get(key) if instance_variable_defined?(key) && @#{state_machine_name}.object.persisted?
|
43
43
|
|
44
44
|
instance_variable_set(key, #{state_machine_klass}.new(
|
45
45
|
self,
|
46
46
|
transition_class: #{transition_klass},
|
47
|
-
association_name: "#{transition_name}"
|
47
|
+
association_name: "#{transition_name}",
|
48
|
+
initial_transition: false
|
48
49
|
))
|
50
|
+
|
51
|
+
if #{initial_transition}
|
52
|
+
if @#{state_machine_name}.history.empty? && #{state_machine_klass}.initial_state
|
53
|
+
@#{state_machine_name}.instance_variable_get(:@storage_adapter).create(nil, #{state_machine_klass}.initial_state) if @#{state_machine_name}.object.persisted?
|
54
|
+
end
|
55
|
+
end
|
56
|
+
@#{state_machine_name}
|
49
57
|
end
|
50
58
|
|
51
59
|
def #{virtual_attribute_name}
|
@@ -86,7 +94,7 @@ module Statesman
|
|
86
94
|
save.tap do
|
87
95
|
@registered_callbacks.each(&:call)
|
88
96
|
@registered_callbacks = []
|
89
|
-
end
|
97
|
+
end
|
90
98
|
end
|
91
99
|
end
|
92
100
|
METHOD
|
@@ -99,7 +107,7 @@ module Statesman
|
|
99
107
|
nil,
|
100
108
|
{ state_machine_klass: state_machine_klass, transition_klass: transition_klass,
|
101
109
|
transition_name: transition_name, virtual_attribute_name: virtual_attribute_name,
|
102
|
-
transition_foreign_key: transition_foreign_key },
|
110
|
+
transition_foreign_key: transition_foreign_key, initial_transition: initial_transition },
|
103
111
|
self
|
104
112
|
)
|
105
113
|
|