nxt_pipeline 0.2.3 → 0.2.4

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: 4103a1a9d5d3220e1b2f6df7776878cc478d7ceec612e0f743fa24f3405b942a
4
- data.tar.gz: 84c9da4b2f27e5814220f14007f7de259267a9dfca168ecfa4a69a97065abbbd
3
+ metadata.gz: 6b545c68dc71684330edc75197b306a9f87abfb90240efe4708d426299902782
4
+ data.tar.gz: d47d498587927798476462538f3c42ea7a151080fe6cdbdccd56e0e12baa9d05
5
5
  SHA512:
6
- metadata.gz: 2a5f3d8efeb773ed700bbcd30aba75415554ab6221e4a95d518d38d9cf32d00c8982eca0e8ad0d46f280b25c845d3a306eda59e6797a8d94d2551740761a8d68
7
- data.tar.gz: 7201abcca537229b6bc27d458a428f84f510c14a0a2c926af8387b2025f719e4336b22c062ba3b591c17adfb73f9c91039b99d2d731897b7d1d51e47ab8ca838
6
+ metadata.gz: ddfe39ac16d28a562a28f42e41205828f8ffe8c448b8135e798aecfd71a2083870e4faffc7e5fc0f1e19625d63eaf0f2930e1b2fbc21a6cb68987647446ae5de
7
+ data.tar.gz: 76ef2fc1b046dac15ed2c5f913048ea304b9ceddcfcd7f6777b9a623026d87e49322ecae0219ce35813b86aabf30867debb667ec69157adebd1adfd0620e6b53
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nxt_pipeline (0.2.2)
4
+ nxt_pipeline (0.2.4)
5
5
  activesupport
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -130,6 +130,24 @@ NxtPipeline::Pipeline.new do |p|
130
130
  end
131
131
  ```
132
132
 
133
+ ### Before and After callbacks
134
+
135
+ You can also define callbacks that run before and after the `#execute` action. Both callback blocks get the pipeline instance (to access stuff like the `log`) and the argument of the pipeline yielded.
136
+
137
+ ```ruby
138
+ NxtPipeline::Pipeline.new do |p|
139
+ p.before_execute do |pipeline, arg|
140
+ # Will be called from within #execute before entering the first step
141
+ end
142
+
143
+ p.after_execute do |pipeline, arg|
144
+ # Will be called from within #execute after executing last step
145
+ end
146
+ end
147
+ ```
148
+
149
+ Note that the `after_execute` callback will not be called, when an error is raised in one of the steps. See the previous section (_Error callbacks_) for how to define callbacks that run in case of errors.
150
+
133
151
 
134
152
  ## Development
135
153
 
@@ -46,10 +46,13 @@ module NxtPipeline
46
46
 
47
47
  def execute(arg, &block)
48
48
  reset_log
49
+ before_execute_callback.call(self, arg) if before_execute_callback.respond_to?(:call)
49
50
  configure(&block) if block_given?
50
- steps.inject(arg) do |argument, step|
51
+ result = steps.inject(arg) do |argument, step|
51
52
  execute_step(step, argument)
52
53
  end
54
+ after_execute_callback.call(self, result) if after_execute_callback.respond_to?(:call)
55
+ result
53
56
  rescue StandardError => error
54
57
  log[current_step] = { status: :failed, reason: "#{error.class}: #{error.message}" }
55
58
  callback = find_error_callback(error)
@@ -64,6 +67,14 @@ module NxtPipeline
64
67
 
65
68
  alias :on_error :on_errors
66
69
 
70
+ def before_execute(&callback)
71
+ self.before_execute_callback = callback
72
+ end
73
+
74
+ def after_execute(&callback)
75
+ self.after_execute_callback = callback
76
+ end
77
+
67
78
  def configure(&block)
68
79
  block.call(self)
69
80
  self
@@ -72,7 +83,7 @@ module NxtPipeline
72
83
  private
73
84
 
74
85
  attr_reader :error_callbacks, :registry
75
- attr_accessor :steps, :current_step, :current_arg, :default_constructor
86
+ attr_accessor :steps, :current_step, :current_arg, :default_constructor, :before_execute_callback, :after_execute_callback
76
87
  attr_writer :log
77
88
 
78
89
  def execute_step(step, arg)
@@ -98,4 +109,4 @@ module NxtPipeline
98
109
  self.current_arg = nil
99
110
  end
100
111
  end
101
- end
112
+ end
@@ -1,3 +1,3 @@
1
1
  module NxtPipeline
2
- VERSION = "0.2.3".freeze
2
+ VERSION = "0.2.4".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nxt_pipeline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nils Sommer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2019-04-23 00:00:00.000000000 Z
13
+ date: 2019-06-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport