status_workflow 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +6 -0
- data/lib/status_workflow.rb +6 -0
- data/lib/status_workflow/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b10d46febb56013a2b4b8a45c9c07594f9eb8a44
|
4
|
+
data.tar.gz: 5483c2e808502d016e2e61bbb3d7d8e6931e1364
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a6ffc8157ba6c080fe72abefcf31b4891d3d4b72e3e7d43a8beccdf3f8d8c83de8aba3b0fde7fe7ae44007a115c20271b6482bc66d04f6e23333fe9c16cd314
|
7
|
+
data.tar.gz: 96fc8efc18e542bf22564aad5c430aa603b3956e090a2ce22baf227cc72688a401a1cae6656c8d6b8f5897018efdcfdc44c80939abece843b139fd6a198002f2
|
data/CHANGELOG
CHANGED
data/lib/status_workflow.rb
CHANGED
@@ -24,6 +24,7 @@ module StatusWorkflow
|
|
24
24
|
|
25
25
|
def status_transition!(intermediate_to_status, final_to_status, prefix = nil)
|
26
26
|
result = nil # what the block yields, return to the user
|
27
|
+
before_status_transition = self.class.instance_variable_get(:@before_status_transition)
|
27
28
|
intermediate_to_status = intermediate_to_status&.to_s
|
28
29
|
final_to_status = final_to_status&.to_s
|
29
30
|
prefix_ = prefix ? "#{prefix}_" : nil
|
@@ -60,9 +61,11 @@ module StatusWorkflow
|
|
60
61
|
end
|
61
62
|
end
|
62
63
|
result = yield
|
64
|
+
before_status_transition&.call
|
63
65
|
rescue
|
64
66
|
# If the block errors, set status to error and record the backtrace
|
65
67
|
error = (["#{$!.class} #{$!.message}"] + $!.backtrace).join("\n")
|
68
|
+
before_status_transition&.call
|
66
69
|
status = read_attribute status_column
|
67
70
|
update_columns status_column => "#{status}_error", status_changed_at_column => Time.now, error_column => error
|
68
71
|
raise
|
@@ -83,6 +86,9 @@ module StatusWorkflow
|
|
83
86
|
end
|
84
87
|
|
85
88
|
module ClassMethods
|
89
|
+
def before_status_transition(&blk)
|
90
|
+
@before_status_transition = blk
|
91
|
+
end
|
86
92
|
def status_workflow(workflows)
|
87
93
|
if workflows.first.last.is_a?(Array)
|
88
94
|
# default mode: use just status
|