nxt_pipeline 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +18 -0
- data/lib/nxt_pipeline/pipeline.rb +14 -3
- data/lib/nxt_pipeline/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b545c68dc71684330edc75197b306a9f87abfb90240efe4708d426299902782
|
4
|
+
data.tar.gz: d47d498587927798476462538f3c42ea7a151080fe6cdbdccd56e0e12baa9d05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddfe39ac16d28a562a28f42e41205828f8ffe8c448b8135e798aecfd71a2083870e4faffc7e5fc0f1e19625d63eaf0f2930e1b2fbc21a6cb68987647446ae5de
|
7
|
+
data.tar.gz: 76ef2fc1b046dac15ed2c5f913048ea304b9ceddcfcd7f6777b9a623026d87e49322ecae0219ce35813b86aabf30867debb667ec69157adebd1adfd0620e6b53
|
data/Gemfile.lock
CHANGED
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
|
data/lib/nxt_pipeline/version.rb
CHANGED
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.
|
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-
|
13
|
+
date: 2019-06-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|