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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '079b49ce08eb72bba135aa10dd2d0c41951f13b7fa0f7b511eed0d1ba97b37d7'
4
- data.tar.gz: 33282f6b73e65a6bd12c90c9951a9e73560a1576843c24f62fcdacdea41aef48
3
+ metadata.gz: 3905e37feab9967d3cf749542c69adaa64280b788a7b862348e6002eff0e863f
4
+ data.tar.gz: d899cfc62cda30aaef508168130884ed1150f49120aae8b2ffe6552a03a61929
5
5
  SHA512:
6
- metadata.gz: f1979896e23d1ae5f608a2cc26f2e5985394a2a6189e4a299bf992b9e0410c2e5b9e46eeaf837a6d1e72197610bc7e007e59691284de749da9aaa92b2e88384a
7
- data.tar.gz: 225f97823bc401675d774a42344d3e62e6692fda45b4a13fe15a4abf27bcb321c3e2e249762e41dc3600a1731ca6e2b65a16db6eec0ac2a17badf3c76dc975e3
6
+ metadata.gz: 3de1e8ee02aa0778e673f97a2a58701ec548a6546f84d0bf2d63db5bf339fa267d61a6ff5193353e83f2ce3cfeb259b2ce2f08cab52150ca675364d018c83611
7
+ data.tar.gz: 65eec50438f474ae1d54c70e4baa6648e91cd8a28a662ece2efcec1a30eaf66350252541049995c66ef221fe77ba4f8bcd1f5a56aa97d9b59d96d731639ba801
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nxt_pipeline (0.2.7)
4
+ nxt_pipeline (0.2.8)
5
5
  activesupport
6
6
 
7
7
  GEM
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.
@@ -15,7 +15,14 @@ module NxtPipeline
15
15
  attr_reader :type, :result, :status, :error, :opts, :index
16
16
 
17
17
  def execute(arg)
18
- self.result = constructor.call(self, arg)
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
@@ -1,3 +1,3 @@
1
1
  module NxtPipeline
2
- VERSION = "0.2.7".freeze
2
+ VERSION = "0.2.8".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.7
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-07-30 00:00:00.000000000 Z
13
+ date: 2019-08-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport