nxt_pipeline 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 562568995097a8f83c10663f6338404b1aea732d7e65f1c151a1d4a76c32a2bb
4
+ data.tar.gz: 3494855a43cdbe7a253e9ee5b07c6c1be7bf7be3e52a2a83da99fcd2c612b2cc
5
+ SHA512:
6
+ metadata.gz: 6efff78864aa95fa547486c301ab7023fa2b1ed623e6f3e80380efaae9b943dd0d35ae251a079d02be8e07faf34ee2d9e60f19a365c4e5496ac16406a5a5223f
7
+ data.tar.gz: e27d108c8cd267b61ac4962b2e395957070e580c66482b124e2f4217c27b2f80cbd3a8eb22d2417fd04b91e2a916279edb5cfc5ce2ac89314191c66effc41fef
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.1
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.1
7
+ before_install: gem install bundler -v 1.17.2
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in nxt_pipeline.gemspec
6
+ gemspec
7
+
8
+ gem 'activesupport'
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nxt_pipeline (0.1.0)
5
+ activesupport
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (5.2.2)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 0.7, < 2)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ concurrent-ruby (1.1.4)
16
+ diff-lcs (1.3)
17
+ i18n (1.5.3)
18
+ concurrent-ruby (~> 1.0)
19
+ minitest (5.11.3)
20
+ rake (10.5.0)
21
+ rspec (3.8.0)
22
+ rspec-core (~> 3.8.0)
23
+ rspec-expectations (~> 3.8.0)
24
+ rspec-mocks (~> 3.8.0)
25
+ rspec-core (3.8.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-expectations (3.8.2)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-mocks (3.8.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.8.0)
33
+ rspec-support (3.8.0)
34
+ thread_safe (0.3.6)
35
+ tzinfo (1.2.5)
36
+ thread_safe (~> 0.1)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ activesupport
43
+ bundler (~> 1.17)
44
+ nxt_pipeline!
45
+ rake (~> 10.0)
46
+ rspec (~> 3.0)
47
+
48
+ BUNDLED WITH
49
+ 1.17.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Nils Sommer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # NxtPipeline
2
+
3
+ nxt_pipeline provides a DSL to structure the processing of an object (oil) through multiple steps by defining pipelines (which process the object) and segments (reusable steps used by the pipeline).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'nxt_pipeline'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install nxt_pipeline
20
+
21
+ ## Usage
22
+
23
+ Look how easy it is.
24
+
25
+ ```ruby
26
+ class UppercaseSegment < NxtPipeline::Segment
27
+ def pipe_through
28
+ words.map(&:uppercase)
29
+ end
30
+ end
31
+
32
+ class SortSegment < NxtPipeline::Segment
33
+ def pipe_through
34
+ words.sort
35
+ end
36
+ end
37
+
38
+ class MyPipeline < NxtPipeline::Pipeline
39
+ pipe_attr :words
40
+
41
+ segment UppercaseSegment
42
+ segment SortSegment
43
+ end
44
+
45
+ MyPipeline.new(words: %w[Ruby is awesome]).call
46
+ # => ["AWESOME", "IS", "RUBY"]
47
+ ```
48
+
49
+ Basically you create a pipeline class that inherits from `NxtPipeline::Pipeline` and name the attribute you want to pass through the pipeline's segments with the `pipe_attr` class method.
50
+
51
+ You can add segments to the pipeline by using the `segment` class method in the pipeline class body. The segment classes inherit from `NxtPipeline::Segment` and have to implement a method `#pipe_through`. Inside of it, you can access the pipeline attr by its reader method (see example above).
52
+
53
+ You can also define behavior to execute when one of the pipelines raises an error.
54
+
55
+ ```ruby
56
+ class MyPipeline < NxtPipeline::Pipeline
57
+ pipe_attr :words
58
+
59
+ segment UppercaseSegment
60
+ segment SortSegment
61
+
62
+ rescue_from StandardError do |error, segment_failed_upon|
63
+ puts "Failed in segment #{segment_failed_upon} with #{error.class}: #{error.message}"
64
+ end
65
+ end
66
+
67
+ pipeline = MyPipeline.new(words: %w[Ruby is awesome])
68
+ pipeline.call
69
+ # => 'Failed in segment uppercase_segment with StandardError: Lorem ipsum'
70
+
71
+ pipeline.burst?
72
+ # => true
73
+ pipeline.burst_segment
74
+ # => 'uppercase_segment'
75
+ ```
76
+
77
+ ## Development
78
+
79
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
80
+
81
+ 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
+
83
+ ## Contributing
84
+
85
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nxt-insurance/nxt_pipeline.
86
+
87
+ ## License
88
+
89
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nxt_pipeline"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+
4
+ require 'nxt_pipeline/version'
5
+ require 'nxt_pipeline/segment'
6
+ require 'nxt_pipeline/pipeline'
7
+
8
+ module NxtPipeline
9
+ class Error < StandardError; end
10
+ end
@@ -0,0 +1,58 @@
1
+ module NxtPipeline
2
+ class Pipeline
3
+ attr_reader :burst_segment
4
+
5
+ def initialize(*attrs)
6
+ extract_pipe_attr_from_init_params(*attrs)
7
+ end
8
+
9
+ def call
10
+ self.segments.reduce(pipe_attr) do |transformed_pipe_attr, segment|
11
+ segment[pipe_attr_name].new(pipe_attr_name => transformed_pipe_attr).pipe_through
12
+ rescue => error
13
+ handle_segment_burst(error, segment)
14
+ end
15
+ end
16
+
17
+ def burst?
18
+ burst_segment.present?
19
+ end
20
+
21
+ class << self
22
+ def pipe_attr(name)
23
+ self.pipe_attr_name = name
24
+ end
25
+
26
+ def mount_segment(name)
27
+ self.segments << name
28
+ end
29
+
30
+ def rescue_segment_burst(*errors, &block)
31
+ self.rescueable_segment_bursts = errors
32
+ self.rescueable_block = block
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ attr_reader :pipe_attr
39
+
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
+ def extract_pipe_attr_from_init_params(*attrs)
46
+ 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)
48
+ end
49
+
50
+ def handle_segment_burst(error, segment)
51
+ @burst_segment = segment.name.split('::').last.underscore
52
+
53
+ self.rescueable_block.call(error, burst_segment) if error.class.in?(rescueable_segment_bursts)
54
+
55
+ raise
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,47 @@
1
+ module NxtPipeline
2
+ class Segment
3
+ def initialize(*args)
4
+ validate_initialize_args(*args).each do |key, value|
5
+ send("#{key}=", value)
6
+ end
7
+ end
8
+
9
+ def pipe_through
10
+ # Public interface of Segment, to be implemented by subclasses.
11
+ raise NotImplementedError
12
+ end
13
+
14
+ def self.[](*args)
15
+ raise ArgumentError, 'Arguments missing' if args.empty?
16
+
17
+ Class.new(self) do
18
+ self.segment_args = args.map(&:to_sym)
19
+
20
+ self.segment_args.each do |segment_arg|
21
+ attr_accessor segment_arg
22
+ end
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ cattr_accessor :segment_args, instance_writer: false, default: []
29
+
30
+ def validate_initialize_args(*args)
31
+ raise ArgumentError, arguments_missing_msg(self.segment_args) if args.empty?
32
+
33
+ keyword_args = args.first
34
+ missing_keyword_args = self.segment_args.reject do |arg|
35
+ keyword_args.include?(arg)
36
+ end
37
+
38
+ raise ArgumentError, arguments_missing_msg(missing_keyword_args) if missing_keyword_args.any?
39
+
40
+ keyword_args.slice(*self.segment_args)
41
+ end
42
+
43
+ def arguments_missing_msg(missing_arg_keys)
44
+ "Arguments missing: #{missing_arg_keys.map { |a| "#{a}:" }.join(', ')}"
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module NxtPipeline
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,41 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "nxt_pipeline/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nxt_pipeline"
8
+ spec.version = NxtPipeline::VERSION
9
+ spec.authors = ["Nils Sommer", "Andreas Robecke", "Raphael Kallensee"]
10
+ spec.email = ["mail@nilssommer.de"]
11
+
12
+ spec.summary = %q{DSL to build Pipeline with mountable Segments to process things.}
13
+ spec.homepage = "https://github.com/nxt-insurance/nxt_pipeline"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/nxt-insurance/nxt_pipeline.git"
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against " \
25
+ "public gem pushes."
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_dependency "activesupport"
38
+ spec.add_development_dependency "bundler", "~> 1.17"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nxt_pipeline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nils Sommer
8
+ - Andreas Robecke
9
+ - Raphael Kallensee
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2019-02-24 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: bundler
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.17'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.17'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rake
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '10.0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '10.0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rspec
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '3.0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '3.0'
71
+ description:
72
+ email:
73
+ - mail@nilssommer.de
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".ruby-version"
81
+ - ".travis.yml"
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/setup
89
+ - lib/nxt_pipeline.rb
90
+ - lib/nxt_pipeline/pipeline.rb
91
+ - lib/nxt_pipeline/segment.rb
92
+ - lib/nxt_pipeline/version.rb
93
+ - nxt_pipeline.gemspec
94
+ homepage: https://github.com/nxt-insurance/nxt_pipeline
95
+ licenses:
96
+ - MIT
97
+ metadata:
98
+ allowed_push_host: https://rubygems.org
99
+ homepage_uri: https://github.com/nxt-insurance/nxt_pipeline
100
+ source_code_uri: https://github.com/nxt-insurance/nxt_pipeline.git
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubygems_version: 3.0.1
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: DSL to build Pipeline with mountable Segments to process things.
120
+ test_files: []