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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1429ec0dd19bb00d60a21a13b222e2152d0e61a
4
- data.tar.gz: 3a418f92be0f9d4ef97722ec7ae420ef0d3ba4e6
3
+ metadata.gz: b10d46febb56013a2b4b8a45c9c07594f9eb8a44
4
+ data.tar.gz: 5483c2e808502d016e2e61bbb3d7d8e6931e1364
5
5
  SHA512:
6
- metadata.gz: 7ba51b05b15489ca77342bb35ad4e179c6fe0a00f5aaccc0c62d25e7b20a43e5eb803b8ff8cc4c6b14dd3f8d3a8952d89acd34cd58a5dc8cba1220fc2e2d382a
7
- data.tar.gz: 734ce3e74ea19d0dcc96606f6bf513b8ac9e8ac034665d28e374c8a1af8f4eff660822e6cdab218a4cfd10b2c8c1fca6c31d69368f5f46a4c8f60fcac7a84cb1
6
+ metadata.gz: 8a6ffc8157ba6c080fe72abefcf31b4891d3d4b72e3e7d43a8beccdf3f8d8c83de8aba3b0fde7fe7ae44007a115c20271b6482bc66d04f6e23333fe9c16cd314
7
+ data.tar.gz: 96fc8efc18e542bf22564aad5c430aa603b3956e090a2ce22baf227cc72688a401a1cae6656c8d6b8f5897018efdcfdc44c80939abece843b139fd6a198002f2
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 3.0.3 / 2018-11-05
2
+
3
+ Enhancements
4
+
5
+ * Provide before_status_transition hook
6
+
1
7
  3.0.2 / 2018-11-05
2
8
 
3
9
  Enhancements
@@ -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
@@ -1,3 +1,3 @@
1
1
  module StatusWorkflow
2
- VERSION = '3.0.2'
2
+ VERSION = '3.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: status_workflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere