nxt_pipeline 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +52 -0
- data/CHANGELOG.md +32 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +41 -2
- data/Guardfile +31 -0
- data/README.md +66 -28
- data/bin/guard +29 -0
- data/bin/rspec +29 -0
- data/lib/nxt_pipeline/pipeline.rb +45 -22
- data/lib/nxt_pipeline/{segment.rb → step.rb} +9 -9
- data/lib/nxt_pipeline/version.rb +1 -1
- data/lib/nxt_pipeline.rb +1 -1
- data/nxt_pipeline.gemspec +1 -0
- metadata +22 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 990043f1b6a4cb543090543a45aa103f915db67ad30a682fcf459d4fc582764d
|
4
|
+
data.tar.gz: e3d2af9e6492d930fe196a886d4c53314055fbd4534110d2257ddd5687157bf1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de30962f57a74e8e3f8f1ef541395bbfac2ed424a58c1638e2b6e83f62fe40529e2d2df9bb6f1b3641894e64f57bc6b02748bef2af018d9cc9262028f7e1b105
|
7
|
+
data.tar.gz: b0170c1be44573b6f9416e01582e7673cc20fb48fccab4aa2492e516f4fde59da92b8c248e157922bdd293c602ce94de209c9b81c81e549b1c0a7ceaf09b276a
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# Ruby CircleCI 2.0 configuration file
|
2
|
+
#
|
3
|
+
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
4
|
+
#
|
5
|
+
version: 2
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
docker:
|
9
|
+
# specify the version you desire here
|
10
|
+
- image: circleci/ruby:2.6.1-node
|
11
|
+
|
12
|
+
working_directory: ~/repo
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- checkout
|
16
|
+
|
17
|
+
# Download and cache dependencies
|
18
|
+
- restore_cache:
|
19
|
+
keys:
|
20
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
21
|
+
|
22
|
+
- run:
|
23
|
+
name: install dependencies
|
24
|
+
command: |
|
25
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
26
|
+
|
27
|
+
- save_cache:
|
28
|
+
paths:
|
29
|
+
- ./vendor/bundle
|
30
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
31
|
+
|
32
|
+
# run tests!
|
33
|
+
- run:
|
34
|
+
name: run tests
|
35
|
+
command: |
|
36
|
+
mkdir /tmp/test-results
|
37
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
|
38
|
+
circleci tests split --split-by=timings)"
|
39
|
+
|
40
|
+
bundle exec rspec \
|
41
|
+
--format progress \
|
42
|
+
--format RspecJunitFormatter \
|
43
|
+
--out /tmp/test-results/rspec.xml \
|
44
|
+
--format progress \
|
45
|
+
$TEST_FILES
|
46
|
+
|
47
|
+
# collect reports
|
48
|
+
- store_test_results:
|
49
|
+
path: /tmp/test-results
|
50
|
+
- store_artifacts:
|
51
|
+
path: /tmp/test-results
|
52
|
+
destination: test-results
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
## Unreleased
|
2
|
+
|
3
|
+
## nxt_pipeline 0.2.0 (March 10, 2019)
|
4
|
+
|
5
|
+
* Added pipeline callback support.
|
6
|
+
|
7
|
+
*Nils Sommer*
|
8
|
+
|
9
|
+
* Renamed class and method names
|
10
|
+
|
11
|
+
Renamed `NxtPipeline::Segment` to `NxtPipeline::Step`.
|
12
|
+
Renamed `NxtPipeline::Pipeline::segment` to `NxtPipeline::Pipeline::step`.
|
13
|
+
Renamed `NxtPipeline::Pipeline#call` to `NxtPipeline::Pipeline#run`.
|
14
|
+
Renamed `NxtPipeline::Pipeline#burst?` to `NxtPipeline::Pipeline#failed?`.
|
15
|
+
Renamed `NxtPipeline::Pipeline#burst_segment` to `NxtPipeline::Pipeline#failed_step`.
|
16
|
+
Renamed `NxtPipeline::Pipeline::rescue_segment_burst` to `NxtPipeline::Pipeline::rescue_errors`.
|
17
|
+
|
18
|
+
*Nils Sommer*
|
19
|
+
|
20
|
+
* Setup [guard](https://github.com/guard/guard) to run specs upon file changes during development.
|
21
|
+
|
22
|
+
*Nils Sommer*
|
23
|
+
|
24
|
+
* Added CHANGELOG file.
|
25
|
+
|
26
|
+
*Nils Sommer*
|
27
|
+
|
28
|
+
## nxt_pipeline 0.1.0 (February 25, 2019)
|
29
|
+
|
30
|
+
* Initial Release.
|
31
|
+
|
32
|
+
*Nils Sommer*
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nxt_pipeline (0.
|
4
|
+
nxt_pipeline (0.2.0)
|
5
5
|
activesupport
|
6
6
|
|
7
7
|
GEM
|
@@ -12,12 +12,45 @@ GEM
|
|
12
12
|
i18n (>= 0.7, < 2)
|
13
13
|
minitest (~> 5.1)
|
14
14
|
tzinfo (~> 1.1)
|
15
|
+
coderay (1.1.2)
|
15
16
|
concurrent-ruby (1.1.4)
|
16
17
|
diff-lcs (1.3)
|
18
|
+
ffi (1.10.0)
|
19
|
+
formatador (0.2.5)
|
20
|
+
guard (2.15.0)
|
21
|
+
formatador (>= 0.2.4)
|
22
|
+
listen (>= 2.7, < 4.0)
|
23
|
+
lumberjack (>= 1.0.12, < 2.0)
|
24
|
+
nenv (~> 0.1)
|
25
|
+
notiffany (~> 0.0)
|
26
|
+
pry (>= 0.9.12)
|
27
|
+
shellany (~> 0.0)
|
28
|
+
thor (>= 0.18.1)
|
29
|
+
guard-compat (1.2.1)
|
30
|
+
guard-rspec (4.7.3)
|
31
|
+
guard (~> 2.1)
|
32
|
+
guard-compat (~> 1.1)
|
33
|
+
rspec (>= 2.99.0, < 4.0)
|
17
34
|
i18n (1.5.3)
|
18
35
|
concurrent-ruby (~> 1.0)
|
36
|
+
listen (3.1.5)
|
37
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
38
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
39
|
+
ruby_dep (~> 1.2)
|
40
|
+
lumberjack (1.0.13)
|
41
|
+
method_source (0.9.2)
|
19
42
|
minitest (5.11.3)
|
43
|
+
nenv (0.3.0)
|
44
|
+
notiffany (0.1.1)
|
45
|
+
nenv (~> 0.1)
|
46
|
+
shellany (~> 0.0)
|
47
|
+
pry (0.12.2)
|
48
|
+
coderay (~> 1.1.0)
|
49
|
+
method_source (~> 0.9.0)
|
20
50
|
rake (10.5.0)
|
51
|
+
rb-fsevent (0.10.3)
|
52
|
+
rb-inotify (0.10.0)
|
53
|
+
ffi (~> 1.0)
|
21
54
|
rspec (3.8.0)
|
22
55
|
rspec-core (~> 3.8.0)
|
23
56
|
rspec-expectations (~> 3.8.0)
|
@@ -31,6 +64,11 @@ GEM
|
|
31
64
|
diff-lcs (>= 1.2.0, < 2.0)
|
32
65
|
rspec-support (~> 3.8.0)
|
33
66
|
rspec-support (3.8.0)
|
67
|
+
rspec_junit_formatter (0.4.1)
|
68
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
69
|
+
ruby_dep (1.5.0)
|
70
|
+
shellany (0.0.1)
|
71
|
+
thor (0.20.3)
|
34
72
|
thread_safe (0.3.6)
|
35
73
|
tzinfo (1.2.5)
|
36
74
|
thread_safe (~> 0.1)
|
@@ -39,11 +77,12 @@ PLATFORMS
|
|
39
77
|
ruby
|
40
78
|
|
41
79
|
DEPENDENCIES
|
42
|
-
activesupport
|
43
80
|
bundler (~> 1.17)
|
81
|
+
guard-rspec
|
44
82
|
nxt_pipeline!
|
45
83
|
rake (~> 10.0)
|
46
84
|
rspec (~> 3.0)
|
85
|
+
rspec_junit_formatter
|
47
86
|
|
48
87
|
BUNDLED WITH
|
49
88
|
1.17.2
|
data/Guardfile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
19
|
+
# rspec may be run, below are examples of the most common uses.
|
20
|
+
# * bundler: 'bundle exec rspec'
|
21
|
+
# * bundler binstubs: 'bin/rspec'
|
22
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
23
|
+
# installed the spring binstubs per the docs)
|
24
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
25
|
+
# * 'just' rspec: 'rspec'
|
26
|
+
|
27
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
28
|
+
watch(%r{^spec/.+_spec\.rb$})
|
29
|
+
watch(%r{^lib/nxt_pipeline/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
30
|
+
watch('spec/spec_helper.rb') { "spec" }
|
31
|
+
end
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
[![CircleCI](https://circleci.com/gh/nxt-insurance/nxt_pipeline.svg?style=svg)](https://circleci.com/gh/nxt-insurance/nxt_pipeline)
|
2
|
+
|
1
3
|
# NxtPipeline
|
2
4
|
|
3
|
-
nxt_pipeline provides a DSL to
|
5
|
+
nxt_pipeline provides a DSL to define pipeline classes which take an object and pass it through multiple steps which can read or modify the object.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -20,66 +22,102 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
## Usage
|
22
24
|
|
23
|
-
|
25
|
+
Define a pipeline by defining class inheriting from `NxtPipeline::Pipeline` as shown above. The following examples shows a pipeline which takes an array of strings and passes it through multiple steps.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
class MyPipeline < NxtPipeline::Pipeline
|
29
|
+
pipe_attr :words
|
30
|
+
|
31
|
+
step UppercaseSegment
|
32
|
+
step SortSegment
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
The steps are classes themselves which inherit from `NxtPipeline::Step` and have to implement a `#pipe_through` method.
|
24
37
|
|
25
38
|
```ruby
|
26
|
-
class UppercaseSegment < NxtPipeline::
|
39
|
+
class UppercaseSegment < NxtPipeline::Step
|
27
40
|
def pipe_through
|
28
41
|
words.map(&:uppercase)
|
29
42
|
end
|
30
43
|
end
|
31
44
|
|
32
|
-
class SortSegment < NxtPipeline::
|
45
|
+
class SortSegment < NxtPipeline::Step
|
33
46
|
def pipe_through
|
34
47
|
words.sort
|
35
48
|
end
|
36
49
|
end
|
50
|
+
```
|
37
51
|
|
38
|
-
class
|
39
|
-
pipe_attr :words
|
40
|
-
|
41
|
-
segment UppercaseSegment
|
42
|
-
segment SortSegment
|
43
|
-
end
|
52
|
+
You can access the pipeline attribute defined by `pipe_attr` in the pipeline class by a reader method which is automatically defined by nxt_pipeline. Don't forget to return the pipeline attribute so that subsequent steps in the pipeline can take it up!
|
44
53
|
|
45
|
-
|
54
|
+
Here's how our little example pipeline behaves like in action:
|
55
|
+
|
56
|
+
```
|
57
|
+
MyPipeline.new(words: %w[Ruby is awesome]).run
|
46
58
|
# => ["AWESOME", "IS", "RUBY"]
|
47
59
|
```
|
48
60
|
|
49
|
-
|
61
|
+
### Callbacks
|
50
62
|
|
51
|
-
You can
|
52
|
-
|
53
|
-
You can also define behavior to execute when one of the pipelines raises an error.
|
63
|
+
You can define callbacks that are automatically invoked for each step in the pipeline.
|
54
64
|
|
55
65
|
```ruby
|
56
66
|
class MyPipeline < NxtPipeline::Pipeline
|
57
|
-
|
67
|
+
before_each_step do
|
68
|
+
# Code run before each step.
|
69
|
+
end
|
58
70
|
|
59
|
-
|
60
|
-
|
71
|
+
after_each_step do
|
72
|
+
# Code run after each step
|
73
|
+
end
|
61
74
|
|
62
|
-
|
63
|
-
|
75
|
+
around_each_step do |pipeline, segment|
|
76
|
+
# Code run before each step
|
77
|
+
segment.call
|
78
|
+
# Code run after each step
|
64
79
|
end
|
65
80
|
end
|
81
|
+
```
|
82
|
+
|
83
|
+
The callback methods are syntactic sugar for [ActiveSupport Callbacks](https://api.rubyonrails.org/classes/ActiveSupport/Callbacks.html), so the same rules apply regarding order or execution.
|
84
|
+
|
85
|
+
### Error handling
|
66
86
|
|
67
|
-
pipeline
|
68
|
-
pipeline.call
|
69
|
-
# => 'Failed in segment uppercase_segment with StandardError: Lorem ipsum'
|
87
|
+
When everything works smoothly the pipeline calls one step after another, passing through the pipeline attribute and returning it as it gets it from the last step. However, you might want to define behavior the pipeline should perform in case one of the steps raises an error.
|
70
88
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
#
|
89
|
+
```ruby
|
90
|
+
class MyPipeline < NxtPipeline::Pipeline
|
91
|
+
rescue_errors StandardError do |error, failed_step|
|
92
|
+
puts "Step #{failed_step} failed with #{error.class}: #{error.message}"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
97
|
+
Keep in mind though that `rescue_errors` will reraise the error it caught. When you rescue this error in your application, the pipeline remembers if and how it failed.
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
pipeline = MyPipeline.new(...)
|
101
|
+
|
102
|
+
begin
|
103
|
+
pipeline.run
|
104
|
+
rescue => e
|
105
|
+
pipeline.failed?
|
106
|
+
#=> true
|
107
|
+
|
108
|
+
pipeline.failed_step
|
109
|
+
#=> :underscored_class_name_of_failed_step
|
110
|
+
end
|
75
111
|
```
|
76
112
|
|
77
113
|
## Development
|
78
114
|
|
79
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `
|
115
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
80
116
|
|
81
117
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
82
118
|
|
119
|
+
You can also run `bin/guard` to automatically run specs when files are saved.
|
120
|
+
|
83
121
|
## Contributing
|
84
122
|
|
85
123
|
Bug reports and pull requests are welcome on GitHub at https://github.com/nxt-insurance/nxt_pipeline.
|
data/bin/guard
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'guard' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("guard", "guard")
|
data/bin/rspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rspec-core", "rspec")
|
@@ -1,56 +1,79 @@
|
|
1
1
|
module NxtPipeline
|
2
2
|
class Pipeline
|
3
|
-
|
3
|
+
include ActiveSupport::Callbacks
|
4
|
+
define_callbacks :each_step_pipe_through
|
5
|
+
|
6
|
+
attr_reader :failed_step
|
4
7
|
|
5
8
|
def initialize(*attrs)
|
6
9
|
extract_pipe_attr_from_init_params(*attrs)
|
7
10
|
end
|
8
11
|
|
9
|
-
def
|
10
|
-
self.
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def run
|
13
|
+
self.class.steps.reduce(pipe_attr) do |transformed_pipe_attr, step|
|
14
|
+
run_callbacks :each_step_pipe_through do
|
15
|
+
step[self.class.pipe_attr_name].new(self.class.pipe_attr_name => transformed_pipe_attr).pipe_through
|
16
|
+
rescue => error
|
17
|
+
handle_segment_burst(error, step)
|
18
|
+
end
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
17
|
-
def
|
18
|
-
|
22
|
+
def failed?
|
23
|
+
failed_step.present?
|
19
24
|
end
|
20
25
|
|
21
26
|
class << self
|
22
27
|
def pipe_attr(name)
|
23
|
-
|
28
|
+
@pipe_attr_name = name
|
24
29
|
end
|
25
30
|
|
26
|
-
def
|
27
|
-
self.
|
31
|
+
def step(name)
|
32
|
+
self.steps << name
|
28
33
|
end
|
29
34
|
|
30
|
-
def
|
31
|
-
|
35
|
+
def rescue_errors(*errors, &block)
|
36
|
+
@rescueable_errors = errors
|
32
37
|
self.rescueable_block = block
|
33
38
|
end
|
39
|
+
|
40
|
+
def before_each_step(*filters, &block)
|
41
|
+
set_callback :each_step_pipe_through, :before, *filters, &block
|
42
|
+
end
|
43
|
+
|
44
|
+
def after_each_step(*filters, &block)
|
45
|
+
set_callback :each_step_pipe_through, :after, *filters, &block
|
46
|
+
end
|
47
|
+
|
48
|
+
def around_each_step(*filters, &block)
|
49
|
+
set_callback :each_step_pipe_through, :around, *filters, &block
|
50
|
+
end
|
51
|
+
|
52
|
+
attr_reader :pipe_attr_name
|
53
|
+
attr_accessor :rescueable_block
|
54
|
+
|
55
|
+
def steps
|
56
|
+
@steps ||= []
|
57
|
+
end
|
58
|
+
|
59
|
+
def rescueable_errors
|
60
|
+
@rescueable_errors ||= []
|
61
|
+
end
|
34
62
|
end
|
35
63
|
|
36
64
|
private
|
37
65
|
|
38
66
|
attr_reader :pipe_attr
|
39
67
|
|
40
|
-
cattr_accessor :pipe_attr_name
|
41
|
-
cattr_accessor :segments, instance_writer: false, default: []
|
42
|
-
cattr_accessor :rescueable_segment_bursts, instance_writer: false, default: []
|
43
|
-
cattr_accessor :rescueable_block, instance_writer: false
|
44
|
-
|
45
68
|
def extract_pipe_attr_from_init_params(*attrs)
|
46
69
|
raise ArgumentError, 'You need to pass a keyword param as argument to #new' unless attrs.first.is_a?(Hash)
|
47
|
-
@pipe_attr = attrs.first.fetch(pipe_attr_name)
|
70
|
+
@pipe_attr = attrs.first.fetch(self.class.pipe_attr_name)
|
48
71
|
end
|
49
72
|
|
50
|
-
def handle_segment_burst(error,
|
51
|
-
@
|
73
|
+
def handle_segment_burst(error, step)
|
74
|
+
@failed_step = step.name.split('::').last.underscore
|
52
75
|
|
53
|
-
self.rescueable_block.call(error,
|
76
|
+
self.class.rescueable_block.call(error, failed_step) if error.class.in?(self.class.rescueable_errors)
|
54
77
|
|
55
78
|
raise
|
56
79
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module NxtPipeline
|
2
|
-
class
|
2
|
+
class Step
|
3
3
|
def initialize(*args)
|
4
4
|
validate_initialize_args(*args).each do |key, value|
|
5
5
|
send("#{key}=", value)
|
@@ -7,7 +7,7 @@ module NxtPipeline
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def pipe_through
|
10
|
-
# Public interface of
|
10
|
+
# Public interface of Step, to be implemented by subclasses.
|
11
11
|
raise NotImplementedError
|
12
12
|
end
|
13
13
|
|
@@ -15,29 +15,29 @@ module NxtPipeline
|
|
15
15
|
raise ArgumentError, 'Arguments missing' if args.empty?
|
16
16
|
|
17
17
|
Class.new(self) do
|
18
|
-
self.
|
18
|
+
self.step_args = args.map(&:to_sym)
|
19
19
|
|
20
|
-
self.
|
21
|
-
attr_accessor
|
20
|
+
self.step_args.each do |step_arg|
|
21
|
+
attr_accessor step_arg
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
private
|
27
27
|
|
28
|
-
cattr_accessor :
|
28
|
+
cattr_accessor :step_args, instance_writer: false, default: []
|
29
29
|
|
30
30
|
def validate_initialize_args(*args)
|
31
|
-
raise ArgumentError, arguments_missing_msg(self.
|
31
|
+
raise ArgumentError, arguments_missing_msg(self.step_args) if args.empty?
|
32
32
|
|
33
33
|
keyword_args = args.first
|
34
|
-
missing_keyword_args = self.
|
34
|
+
missing_keyword_args = self.step_args.reject do |arg|
|
35
35
|
keyword_args.include?(arg)
|
36
36
|
end
|
37
37
|
|
38
38
|
raise ArgumentError, arguments_missing_msg(missing_keyword_args) if missing_keyword_args.any?
|
39
39
|
|
40
|
-
keyword_args.slice(*self.
|
40
|
+
keyword_args.slice(*self.step_args)
|
41
41
|
end
|
42
42
|
|
43
43
|
def arguments_missing_msg(missing_arg_keys)
|
data/lib/nxt_pipeline/version.rb
CHANGED
data/lib/nxt_pipeline.rb
CHANGED
data/nxt_pipeline.gemspec
CHANGED
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
|
|
36
36
|
|
37
37
|
spec.add_dependency "activesupport"
|
38
38
|
spec.add_development_dependency "bundler", "~> 1.17"
|
39
|
+
spec.add_development_dependency "guard-rspec"
|
39
40
|
spec.add_development_dependency "rake", "~> 10.0"
|
40
41
|
spec.add_development_dependency "rspec", "~> 3.0"
|
41
42
|
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
|
+
version: 0.2.0
|
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-03-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -40,6 +40,20 @@ dependencies:
|
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '1.17'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: guard-rspec
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
43
57
|
- !ruby/object:Gem::Dependency
|
44
58
|
name: rake
|
45
59
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,20 +89,25 @@ executables: []
|
|
75
89
|
extensions: []
|
76
90
|
extra_rdoc_files: []
|
77
91
|
files:
|
92
|
+
- ".circleci/config.yml"
|
78
93
|
- ".gitignore"
|
79
94
|
- ".rspec"
|
80
95
|
- ".ruby-version"
|
81
96
|
- ".travis.yml"
|
97
|
+
- CHANGELOG.md
|
82
98
|
- Gemfile
|
83
99
|
- Gemfile.lock
|
100
|
+
- Guardfile
|
84
101
|
- LICENSE.txt
|
85
102
|
- README.md
|
86
103
|
- Rakefile
|
87
104
|
- bin/console
|
105
|
+
- bin/guard
|
106
|
+
- bin/rspec
|
88
107
|
- bin/setup
|
89
108
|
- lib/nxt_pipeline.rb
|
90
109
|
- lib/nxt_pipeline/pipeline.rb
|
91
|
-
- lib/nxt_pipeline/
|
110
|
+
- lib/nxt_pipeline/step.rb
|
92
111
|
- lib/nxt_pipeline/version.rb
|
93
112
|
- nxt_pipeline.gemspec
|
94
113
|
homepage: https://github.com/nxt-insurance/nxt_pipeline
|