nxt_pipeline 0.4.0 → 0.4.1

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: e8762564262fbcc4274226dd10acd423e960f31624ae20ca539a4951a626e211
4
- data.tar.gz: 17f1adb27f76aaddf71e2dd00ae303e8837560e4fdfae911a98812f30408e541
3
+ metadata.gz: 5d27e24e15af26cd6a1e617ee4a5e71a7b3b556af42983625800e7e74e61f0ef
4
+ data.tar.gz: b2b21c668222af41422878246fc179f6fc25174e23a7873e536df1df2dc64966
5
5
  SHA512:
6
- metadata.gz: efb282aef978706713a0f76332a66298c99d5278794e6935742d08a5d54d271d9c01a633e0c8fcf7d5b67a4c0f945d3fe4de64b871558e7e4a80ac5e87088264
7
- data.tar.gz: 48b4ba6cbb45a9a7f2848e70bc3bd4e6bde884badf820e74cda8d1fea69903f5119204bc073f5f8b6e6386ef6c805f5b0e009938dd881a024d8842947a3697e5
6
+ metadata.gz: 03d15d8834d22ca23f4567cac7e8e0d01a77818468e40866a964c164c9fb4adbd59d0a5a79c9acfaee434c44f0f0a2590a982173b107fd9f581cf7f68e381a8b
7
+ data.tar.gz: ed153b7d64fa2c45314cdbb494e5567dc7fda6d8c6f848d3596a979c330a3e4f03e6eaf0f18a77b43b160f0dcfabaf99df18c6f6ba847c797d9830b099f93535
@@ -7,7 +7,9 @@ jobs:
7
7
  build:
8
8
  docker:
9
9
  # specify the version you desire here
10
- - image: circleci/ruby:2.6.1-node
10
+ - image: circleci/ruby:2.7.0-node
11
+ environment:
12
+ BUNDLER_VERSION: 2.1.4
11
13
 
12
14
  working_directory: ~/repo
13
15
 
@@ -19,6 +21,8 @@ jobs:
19
21
  keys:
20
22
  - v1-dependencies-{{ checksum "Gemfile.lock" }}
21
23
 
24
+ - run: gem install bundler --version $BUNDLER_VERSION
25
+
22
26
  - run:
23
27
  name: install dependencies
24
28
  command: |
data/.pryrc ADDED
@@ -0,0 +1,6 @@
1
+ if defined?(PryByebug)
2
+ Pry.commands.alias_command 'c', 'continue'
3
+ Pry.commands.alias_command 's', 'step'
4
+ Pry.commands.alias_command 'n', 'next'
5
+ Pry.commands.alias_command 'f', 'finish'
6
+ end
@@ -1 +1 @@
1
- 2.6.3
1
+ 2.7.0
@@ -1,4 +1,6 @@
1
- ## Unreleased
1
+ ## nxt_pipeline 0.4.1 (March 13, 2020)
2
+
3
+ * Fix deprecation warnings for Ruby 2.7
2
4
 
3
5
  ## nxt_pipeline 0.2.0 (March 10, 2019)
4
6
 
@@ -1,20 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nxt_pipeline (0.4.0)
4
+ nxt_pipeline (0.4.1)
5
5
  activesupport
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (6.0.0)
10
+ activesupport (6.0.2.1)
11
11
  concurrent-ruby (~> 1.0, >= 1.0.2)
12
12
  i18n (>= 0.7, < 2)
13
13
  minitest (~> 5.1)
14
14
  tzinfo (~> 1.1)
15
- zeitwerk (~> 2.1, >= 2.1.8)
15
+ zeitwerk (~> 2.2)
16
+ byebug (11.1.1)
16
17
  coderay (1.1.2)
17
- concurrent-ruby (1.1.5)
18
+ concurrent-ruby (1.1.6)
18
19
  diff-lcs (1.3)
19
20
  ffi (1.11.1)
20
21
  formatador (0.2.5)
@@ -32,7 +33,7 @@ GEM
32
33
  guard (~> 2.1)
33
34
  guard-compat (~> 1.1)
34
35
  rspec (>= 2.99.0, < 4.0)
35
- i18n (1.6.0)
36
+ i18n (1.8.2)
36
37
  concurrent-ruby (~> 1.0)
37
38
  listen (3.1.5)
38
39
  rb-fsevent (~> 0.9, >= 0.9.4)
@@ -40,7 +41,7 @@ GEM
40
41
  ruby_dep (~> 1.2)
41
42
  lumberjack (1.0.13)
42
43
  method_source (0.9.2)
43
- minitest (5.11.3)
44
+ minitest (5.14.0)
44
45
  nenv (0.3.0)
45
46
  notiffany (0.1.1)
46
47
  nenv (~> 0.1)
@@ -48,44 +49,47 @@ GEM
48
49
  pry (0.12.2)
49
50
  coderay (~> 1.1.0)
50
51
  method_source (~> 0.9.0)
51
- rake (12.3.3)
52
+ pry-byebug (3.8.0)
53
+ byebug (~> 11.0)
54
+ pry (~> 0.10)
55
+ rake (13.0.1)
52
56
  rb-fsevent (0.10.3)
53
57
  rb-inotify (0.10.0)
54
58
  ffi (~> 1.0)
55
- rspec (3.8.0)
56
- rspec-core (~> 3.8.0)
57
- rspec-expectations (~> 3.8.0)
58
- rspec-mocks (~> 3.8.0)
59
- rspec-core (3.8.1)
60
- rspec-support (~> 3.8.0)
61
- rspec-expectations (3.8.4)
59
+ rspec (3.9.0)
60
+ rspec-core (~> 3.9.0)
61
+ rspec-expectations (~> 3.9.0)
62
+ rspec-mocks (~> 3.9.0)
63
+ rspec-core (3.9.0)
64
+ rspec-support (~> 3.9.0)
65
+ rspec-expectations (3.9.0)
62
66
  diff-lcs (>= 1.2.0, < 2.0)
63
- rspec-support (~> 3.8.0)
64
- rspec-mocks (3.8.1)
67
+ rspec-support (~> 3.9.0)
68
+ rspec-mocks (3.9.0)
65
69
  diff-lcs (>= 1.2.0, < 2.0)
66
- rspec-support (~> 3.8.0)
67
- rspec-support (3.8.2)
70
+ rspec-support (~> 3.9.0)
71
+ rspec-support (3.9.0)
68
72
  rspec_junit_formatter (0.4.1)
69
73
  rspec-core (>= 2, < 4, != 2.12.0)
70
74
  ruby_dep (1.5.0)
71
75
  shellany (0.0.1)
72
76
  thor (0.20.3)
73
77
  thread_safe (0.3.6)
74
- tzinfo (1.2.5)
78
+ tzinfo (1.2.6)
75
79
  thread_safe (~> 0.1)
76
- zeitwerk (2.1.9)
80
+ zeitwerk (2.3.0)
77
81
 
78
82
  PLATFORMS
79
83
  ruby
80
84
 
81
85
  DEPENDENCIES
82
- bundler (~> 1.17)
86
+ bundler (~> 2.1)
83
87
  guard-rspec
84
88
  nxt_pipeline!
85
- pry
86
- rake (~> 12.3)
89
+ pry-byebug
90
+ rake (~> 13.0)
87
91
  rspec (~> 3.0)
88
92
  rspec_junit_formatter
89
93
 
90
94
  BUNDLED WITH
91
- 1.17.2
95
+ 2.1.4
data/README.md CHANGED
@@ -192,55 +192,12 @@ end
192
192
 
193
193
  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.
194
194
 
195
- ### DSL
195
+ ### Step resolvers
196
196
 
197
- The gem also comes with an easy DSL to make pipeline handling in your code more convenient.
198
- Simply include NxtPipeline::Dsl in your class:
197
+ NxtPipeline is using so called step_resolvers to find the constructor for a given step by the arguments passed in.
198
+ You can also use this if you are not fine with resolving the constructor from the step argument. Check out the
199
+ `nxt_pipeline/spec/step_resolver_spec.rb` for examples how you can implement your own step_resolvers.
199
200
 
200
- ```ruby
201
- class MyAwesomeClass
202
- include NxtPipeline::Dsl
203
-
204
- # register a pipeline with a name and a block
205
- pipeline :validation do |p|
206
- pipeline.constructor(:validate) do |step, arg:|
207
- result = step.validator.call(arg: arg)
208
- result && { arg: result }
209
- end
210
-
211
- pipeline.step :validate, validator: NameValidator
212
- pipeline.step :validate, validator: AdressValidator
213
- pipeline.step :validate, validator: BankAccountValidator
214
- pipeline.step :validate, validator: PhoneNumberValidator
215
-
216
- p.on_error ValidationError do |step, opts, error|
217
- # ...
218
- end
219
- end
220
-
221
- pipeline :execution do |p|
222
- p.step do |_, arg:|
223
- { arg: arg.upcase }
224
- end
225
-
226
- p.on_error MyCustomError do |step, opts, error|
227
- # nesting pipelines also works
228
- pipeline(:error).execute(error)
229
- end
230
- end
231
-
232
- pipeline :error do |p|
233
- p.step do |_, error|
234
- error # do something here
235
- end
236
- end
237
-
238
- def call(arg)
239
- # execute a pipeline simply by fetching it and calling execute on it as you would normally
240
- pipeline(:execution).execute(arg: arg)
241
- end
242
- end
243
- ```
244
201
 
245
202
  ## Topics
246
203
  - Step orchestration (chainable steps)
@@ -5,7 +5,6 @@ require 'nxt_pipeline/constructor'
5
5
  require 'nxt_pipeline/pipeline'
6
6
  require 'nxt_pipeline/step'
7
7
  require 'nxt_pipeline/error_callback'
8
- require 'nxt_pipeline/dsl'
9
8
 
10
9
  module NxtPipeline
11
10
  end
@@ -1,13 +1,20 @@
1
1
  module NxtPipeline
2
2
  class Constructor
3
- def initialize(name, opts, block)
3
+ def initialize(name, **opts, &block)
4
4
  @name = name
5
5
  @block = block
6
6
  @opts = opts
7
7
  end
8
8
 
9
9
  attr_reader :opts, :block
10
-
11
- delegate :call, :arity, to: :block
10
+
11
+ delegate :arity, to: :block
12
+
13
+ def call(*args, **opts, &block)
14
+ # ActiveSupport's #delegate does not properly handle keyword arg passing
15
+ # in the latest released version. Thefore we bypass delegation by reimplementing
16
+ # the method ourselves. This is already fixed in Rails master though.
17
+ self.block.call(*args, **opts, &block)
18
+ end
12
19
  end
13
20
  end
@@ -1,6 +1,6 @@
1
1
  module NxtPipeline
2
2
  class ErrorCallback
3
- def initialize(errors, halt_on_error, callback)
3
+ def initialize(errors, halt_on_error, &callback)
4
4
  @errors = errors
5
5
  @halt_on_error = halt_on_error
6
6
  @callback = callback
@@ -25,7 +25,7 @@ module NxtPipeline
25
25
  name = name.to_sym
26
26
  raise StandardError, "Already registered step :#{name}" if constructors[name]
27
27
 
28
- constructors[name] = Constructor.new(name, opts, constructor)
28
+ constructors[name] = Constructor.new(name, **opts, &constructor)
29
29
 
30
30
  return unless opts.fetch(:default, false)
31
31
  set_default_constructor(name)
@@ -50,7 +50,7 @@ module NxtPipeline
50
50
  # fall back to :inline if no type is given
51
51
  argument ||= :inline
52
52
  opts.reverse_merge!(to_s: argument)
53
- Constructor.new(:inline, opts, block)
53
+ Constructor.new(:inline, **opts, &block)
54
54
  else
55
55
  constructor = step_resolvers.lazy.map do |resolver|
56
56
  resolver.call(argument)
@@ -78,6 +78,16 @@ module NxtPipeline
78
78
  result = steps.inject(changeset) do |changeset, step|
79
79
  execute_step(step, **changeset)
80
80
  rescue StandardError => error
81
+ logger_for_error = logger
82
+
83
+ error.define_singleton_method :details do
84
+ OpenStruct.new(
85
+ changeset: changeset,
86
+ logger: logger_for_error,
87
+ step: step
88
+ )
89
+ end
90
+
81
91
  callback = find_error_callback(error)
82
92
  raise unless callback && callback.continue_after_error?
83
93
  handle_step_error(error)
@@ -100,7 +110,7 @@ module NxtPipeline
100
110
  end
101
111
 
102
112
  def on_errors(*errors, halt_on_error: true, &callback)
103
- error_callbacks << ErrorCallback.new(errors, halt_on_error, callback)
113
+ error_callbacks << ErrorCallback.new(errors, halt_on_error, &callback)
104
114
  end
105
115
 
106
116
  alias :on_error :on_errors
@@ -32,10 +32,11 @@ module NxtPipeline
32
32
  if_guard_args = guard_args.take(if_guard.arity)
33
33
  unless_guard_guard_args = guard_args.take(unless_guard.arity)
34
34
 
35
- if !unless_guard.call(*unless_guard_guard_args) && if_guard.call(*if_guard_args)
35
+ if !instrumentalize_callable(unless_guard, unless_guard_guard_args) && instrumentalize_callable(if_guard, if_guard_args)
36
36
  constructor_args = [self, changeset]
37
37
  constructor_args = constructor_args.take(constructor.arity)
38
- self.result = constructor.call(*constructor_args)
38
+
39
+ self.result = instrumentalize_callable(constructor, constructor_args)
39
40
  end
40
41
 
41
42
  set_status
@@ -54,6 +55,14 @@ module NxtPipeline
54
55
 
55
56
  attr_writer :result, :status, :error, :mapped_options
56
57
  attr_reader :constructor, :options_mapper
58
+
59
+ def instrumentalize_callable(callable, args)
60
+ if args.last.is_a?(Hash)
61
+ callable.call(*args.take(args.length - 1), **args.last)
62
+ else
63
+ callable.call(*args)
64
+ end
65
+ end
57
66
 
58
67
  def if_guard
59
68
  opts.fetch(:if) { guard(true) }
@@ -1,4 +1,4 @@
1
1
  module NxtPipeline
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.4.1".freeze
3
3
  end
4
4
 
@@ -35,9 +35,9 @@ Gem::Specification.new do |spec|
35
35
  spec.require_paths = ["lib"]
36
36
 
37
37
  spec.add_dependency "activesupport"
38
- spec.add_development_dependency "bundler", "~> 1.17"
38
+ spec.add_development_dependency "bundler", "~> 2.1"
39
39
  spec.add_development_dependency "guard-rspec"
40
- spec.add_development_dependency "rake", "~> 12.3"
40
+ spec.add_development_dependency "rake", "~> 13.0"
41
41
  spec.add_development_dependency "rspec", "~> 3.0"
42
- spec.add_development_dependency "pry"
42
+ spec.add_development_dependency "pry-byebug"
43
43
  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.4.0
4
+ version: 0.4.1
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-08-22 00:00:00.000000000 Z
13
+ date: 2020-03-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -32,14 +32,14 @@ dependencies:
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: '1.17'
35
+ version: '2.1'
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: '1.17'
42
+ version: '2.1'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: guard-rspec
45
45
  requirement: !ruby/object:Gem::Requirement
@@ -60,14 +60,14 @@ dependencies:
60
60
  requirements:
61
61
  - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: '12.3'
63
+ version: '13.0'
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - "~>"
69
69
  - !ruby/object:Gem::Version
70
- version: '12.3'
70
+ version: '13.0'
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rspec
73
73
  requirement: !ruby/object:Gem::Requirement
@@ -83,7 +83,7 @@ dependencies:
83
83
  - !ruby/object:Gem::Version
84
84
  version: '3.0'
85
85
  - !ruby/object:Gem::Dependency
86
- name: pry
86
+ name: pry-byebug
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
89
  - - ">="
@@ -105,6 +105,7 @@ extra_rdoc_files: []
105
105
  files:
106
106
  - ".circleci/config.yml"
107
107
  - ".gitignore"
108
+ - ".pryrc"
108
109
  - ".rspec"
109
110
  - ".ruby-version"
110
111
  - ".travis.yml"
@@ -121,7 +122,6 @@ files:
121
122
  - bin/setup
122
123
  - lib/nxt_pipeline.rb
123
124
  - lib/nxt_pipeline/constructor.rb
124
- - lib/nxt_pipeline/dsl.rb
125
125
  - lib/nxt_pipeline/error_callback.rb
126
126
  - lib/nxt_pipeline/logger.rb
127
127
  - lib/nxt_pipeline/pipeline.rb
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  - !ruby/object:Gem::Version
151
151
  version: '0'
152
152
  requirements: []
153
- rubygems_version: 3.0.3
153
+ rubygems_version: 3.1.2
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: DSL to build Pipeline with mountable Segments to process things.
@@ -1,48 +0,0 @@
1
- module NxtPipeline
2
- module Dsl
3
- module ClassMethods
4
- def pipeline(name = :default, parent = NxtPipeline::Pipeline, &block)
5
- name = name.to_sym
6
- raise ArgumentError, "No block given!" unless block_given?
7
- raise_already_registered_error(name) if pipeline_registry.key?(name)
8
- register_pipeline(name, block, parent)
9
- end
10
-
11
- def pipeline!(name, parent = NxtPipeline::Pipeline, &block)
12
- raise ArgumentError, "No block given!" unless block_given?
13
- register_pipeline(name, block, parent)
14
- end
15
-
16
- private
17
-
18
- def inherited(child)
19
- child.instance_variable_set(:@pipeline_registry, pipeline_registry.deep_dup)
20
- end
21
-
22
- def raise_already_registered_error(name)
23
- raise KeyError, "Already registered a pipeline #{name}. Call pipeline! to overwrite already registered pipelines"
24
- end
25
-
26
- def pipeline_registry
27
- @pipeline_registry ||= ActiveSupport::HashWithIndifferentAccess.new
28
- end
29
-
30
- def register_pipeline(name, block, parent)
31
- pipeline_registry[name] = { config: block, parent: parent }
32
- end
33
- end
34
-
35
- def self.included(base)
36
- base.extend(ClassMethods)
37
-
38
- def pipeline(name = :default)
39
- registry = self.class.send(:pipeline_registry)
40
- entry = registry.fetch(name) { raise KeyError, "No pipeline #{name} registered"}
41
- config = entry.fetch(:config)
42
- pipeline = entry.fetch(:parent).new
43
- instance_exec(pipeline, &config)
44
- pipeline
45
- end
46
- end
47
- end
48
- end