statesman-multi_state 0.2.7 → 0.2.8
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: 56b6d12e6735645ee756e41faf3c25a9db55ce2185555f996e0d97c20abaabc1
|
|
4
|
+
data.tar.gz: 5f3bc6ad945f8b2b15fc285a14be068da5aa8d3911ed34fdce80dcdbedd7745c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 10d154e23d0d77bebcbc88f8e9aaad0f3ba92897a1ddfe53265486ecadaca65bc79e2b6c028c2294b290528bbcbf5fa71488e059fa65b890932d8524d7fff41b
|
|
7
|
+
data.tar.gz: 9cff0f4741c416da6696728115b777809f3d45230988786fc861abee6a2e43b5b887aac20c1a3765bed3bfdf5d80f36af0c57df7d8f4ec94994b6b36f57bf07f
|
|
@@ -27,7 +27,15 @@ module Statesman
|
|
|
27
27
|
|
|
28
28
|
define_in_state(base, query_builder, join_name, field_name)
|
|
29
29
|
define_not_in_state(base, query_builder, join_name, field_name)
|
|
30
|
-
|
|
30
|
+
|
|
31
|
+
define_method(:reload) do |*a|
|
|
32
|
+
instance = super(*a)
|
|
33
|
+
if instance.respond_to?(:"#{field_name}_state_machine", true)
|
|
34
|
+
instance.send(:"#{field_name}_state_machine").reset
|
|
35
|
+
end
|
|
36
|
+
instance
|
|
37
|
+
end
|
|
38
|
+
end
|
|
31
39
|
|
|
32
40
|
private
|
|
33
41
|
|
|
@@ -64,12 +64,6 @@ module Statesman
|
|
|
64
64
|
Hash[self.class.#{field_name}_human_wrapper]
|
|
65
65
|
.invert[#{field_name}_current_state]
|
|
66
66
|
end
|
|
67
|
-
|
|
68
|
-
private
|
|
69
|
-
|
|
70
|
-
def #{field_name}
|
|
71
|
-
#{field_name}_current_state
|
|
72
|
-
end
|
|
73
67
|
CODE
|
|
74
68
|
|
|
75
69
|
include(const_set("#{field_name}#{SecureRandom.hex(4)}_mod".classify, Module.new).tap do |mod|
|
|
@@ -90,13 +84,8 @@ module Statesman
|
|
|
90
84
|
class_eval <<~METHOD, __FILE__, __LINE__ + 1
|
|
91
85
|
def save_with_state(**options)
|
|
92
86
|
@registered_callbacks ||= []
|
|
93
|
-
if #{virtual_attribute_name}
|
|
94
|
-
|
|
95
|
-
@registered_callbacks << -> { #{field_name}_transition_to(#{virtual_attribute_name}, **options) }
|
|
96
|
-
else
|
|
97
|
-
errors.add(:#{field_name}, :invalid_transition, message: "cannot transition from \#{#{field_name}} to \#{#{virtual_attribute_name}}")
|
|
98
|
-
return false
|
|
99
|
-
end
|
|
87
|
+
if #{virtual_attribute_name}_changed? && #{field_name}_can_transition_to?(#{virtual_attribute_name})
|
|
88
|
+
@registered_callbacks << -> { #{field_name}_transition_to(#{virtual_attribute_name}, **options) }
|
|
100
89
|
end
|
|
101
90
|
|
|
102
91
|
if defined?(super)
|