nxt_pipeline 0.2.7 → 0.2.8
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 +14 -1
- data/lib/nxt_pipeline/step.rb +20 -1
- 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: 3905e37feab9967d3cf749542c69adaa64280b788a7b862348e6002eff0e863f
|
4
|
+
data.tar.gz: d899cfc62cda30aaef508168130884ed1150f49120aae8b2ffe6552a03a61929
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3de1e8ee02aa0778e673f97a2a58701ec548a6546f84d0bf2d63db5bf339fa267d61a6ff5193353e83f2ce3cfeb259b2ce2f08cab52150ca675364d018c83611
|
7
|
+
data.tar.gz: 65eec50438f474ae1d54c70e4baa6648e91cd8a28a662ece2efcec1a30eaf66350252541049995c66ef221fe77ba4f8bcd1f5a56aa97d9b59d96d731639ba801
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -89,7 +89,7 @@ pipeline.execute('initial argument')
|
|
89
89
|
|
90
90
|
# Or run the steps directly using block syntax
|
91
91
|
|
92
|
-
pipeline.execute do |p|
|
92
|
+
pipeline.execute('initial argument') do |p|
|
93
93
|
p.step :service, service_class: MyServiceClass, to_s: 'First step'
|
94
94
|
p.step :service, service_class: MyOtherServiceClass, to_s: 'Second step'
|
95
95
|
p.step :job, job_class: MyJobClass # to_s is optional
|
@@ -126,6 +126,19 @@ pipeline.steps.first
|
|
126
126
|
@type=:transformer>
|
127
127
|
```
|
128
128
|
|
129
|
+
### Guard clauses
|
130
|
+
|
131
|
+
You can also define guard clauses that take a proc to prevent the execution of a step.
|
132
|
+
When the guard takes an argument the step argument is yielded.
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
pipeline.execute('initial argument') do |p|
|
136
|
+
p.step :service, service_class: MyServiceClass, if: -> (arg) { arg == 'initial argument' }
|
137
|
+
p.step :service, service_class: MyOtherServiceClass, unless: -> { false }
|
138
|
+
end
|
139
|
+
|
140
|
+
```
|
141
|
+
|
129
142
|
### Error callbacks
|
130
143
|
|
131
144
|
Apart from defining constructors and steps you can also define error callbacks.
|
data/lib/nxt_pipeline/step.rb
CHANGED
@@ -15,7 +15,14 @@ module NxtPipeline
|
|
15
15
|
attr_reader :type, :result, :status, :error, :opts, :index
|
16
16
|
|
17
17
|
def execute(arg)
|
18
|
-
|
18
|
+
guard_args = [arg, self]
|
19
|
+
if_guard_args = guard_args.take(if_guard.arity)
|
20
|
+
unless_guard_guard_args = guard_args.take(unless_guard.arity)
|
21
|
+
|
22
|
+
if unless_guard.call(*unless_guard_guard_args) && if_guard.call(*if_guard_args)
|
23
|
+
self.result = constructor.call(self, arg)
|
24
|
+
end
|
25
|
+
|
19
26
|
set_status
|
20
27
|
result
|
21
28
|
rescue StandardError => e
|
@@ -37,6 +44,18 @@ module NxtPipeline
|
|
37
44
|
attr_writer :result, :status, :error
|
38
45
|
attr_reader :constructor
|
39
46
|
|
47
|
+
def if_guard
|
48
|
+
opts.fetch(:if) { no_guard }
|
49
|
+
end
|
50
|
+
|
51
|
+
def unless_guard
|
52
|
+
opts.fetch(:unless) { no_guard }
|
53
|
+
end
|
54
|
+
|
55
|
+
def no_guard
|
56
|
+
-> { true }
|
57
|
+
end
|
58
|
+
|
40
59
|
def define_attr_readers(opts)
|
41
60
|
opts.each do |key, value|
|
42
61
|
define_singleton_method key.to_s do
|
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.8
|
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-08-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|