pipelined 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a1c284fb7f72ac4805cf7bae8e9039adfef63607ad4771dcd253d2cb661f3970
4
+ data.tar.gz: 6754fb26df8ce1692f6a9e88a6e1d4214fec070c52f53a0217486e7aeb6356c2
5
+ SHA512:
6
+ metadata.gz: 5f2e5fe6d66029adc58e4ac9938de46e5574d562a56e6891f9bd804473497cc9c42cd8c4581c0429eafbde78344a519ca7cc7b9f7f0a6a6e0543633a1ff4fcf7
7
+ data.tar.gz: 2101a1b04e10a83574286ef50e66ff45e8e94bdaa5b57a4bec3570e9c116edc57b016b422da317a0e1a18e71ea3f85074914e2763088d859d3faaa3722939cb6
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-01-24
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 TODO: Write your name
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,37 @@
1
+ # Pipelined
2
+
3
+ Minimalistic gem for building pipeline architectured services.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ ```bash
10
+ bundle add pipelined
11
+ ```
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ ```bash
16
+ gem install pipelined
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```rb
22
+ env = ApplicationEnvironment
23
+ pipeline = Pipelined::Pipeline.new
24
+ pipeline.use(SomeMiddleware)
25
+ pipeline.insert_before(SomeMiddleware, OtherMiddleware)
26
+ pipeline.call(env) { env.result }
27
+ ```
28
+
29
+ ## Development
30
+
31
+ 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.
32
+
33
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## License
36
+
37
+ 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,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:rspec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %w[rspec rubocop]
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pipelined
4
+ class Middleware
5
+ attr_reader :app, :env
6
+
7
+ def initialize(app, env)
8
+ @app = app
9
+ @env = env
10
+ end
11
+
12
+ def call
13
+ raise(NotImplementedError)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pipelined
4
+ class Pipeline
5
+ def initialize(middlewares = [])
6
+ @middlewares = middlewares
7
+ @uniqed = false
8
+ end
9
+
10
+ def use(middleware)
11
+ @uniqed = false
12
+ @middlewares << middleware
13
+ end
14
+
15
+ def call(env, &final)
16
+ final ||= ->(mod_env) { mod_env }
17
+
18
+ uniq_middlewares!.reverse!
19
+ .reduce(final) { |acc, elem| ->(mod_env) { elem.new(acc, mod_env).call } }
20
+ .call(env)
21
+ end
22
+
23
+ def size
24
+ uniq_middlewares!.size
25
+ end
26
+
27
+ def index(middleware)
28
+ @middlewares.index(middleware)
29
+ end
30
+
31
+ def index!(middleware)
32
+ idx = index(middleware)
33
+ return idx if idx
34
+
35
+ raise(ArgumentError)
36
+ end
37
+
38
+ def insert(index, middleware)
39
+ @uniqed = false
40
+ @middlewares.insert(index, middleware)
41
+ end
42
+
43
+ def insert_before(before, middleware)
44
+ insert(index!(before), middleware)
45
+ end
46
+
47
+ def insert_after(after, middleware)
48
+ insert(index!(after) + 1, middleware)
49
+ end
50
+
51
+ def replace(replaced, middleware)
52
+ @uniqed = false
53
+ @middlewares[index!(replaced)] = middleware
54
+ end
55
+
56
+ def swap(first, second)
57
+ first_idx = index!(first)
58
+ second_idx = index!(second)
59
+ @middlewares[first_idx] = second
60
+ @middlewares[second_idx] = first
61
+ end
62
+
63
+ def delete(middleware)
64
+ @middlewares.delete(middleware)
65
+ end
66
+
67
+ private
68
+
69
+ def uniq_middlewares!
70
+ return @middlewares if @uniqed
71
+
72
+ @uniqed = true
73
+ @middlewares.uniq!
74
+ @middlewares
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pipelined
4
+ VERSION = '0.1.0'
5
+ public_constant :VERSION
6
+ end
data/lib/pipelined.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pipelined/version'
4
+ require 'pipelined/pipeline'
5
+ require 'pipelined/middleware'
6
+
7
+ module Pipelined; end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pipelined
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "@aevula"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-04-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Minimalistic gem for building pipeline architectured services
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - CHANGELOG.md
20
+ - LICENSE.txt
21
+ - README.md
22
+ - Rakefile
23
+ - lib/pipelined.rb
24
+ - lib/pipelined/middleware.rb
25
+ - lib/pipelined/pipeline.rb
26
+ - lib/pipelined/version.rb
27
+ homepage: https://github.com/aevula/pipelined
28
+ licenses:
29
+ - MIT
30
+ metadata:
31
+ homepage_uri: https://github.com/aevula/pipelined
32
+ source_code_uri: https://github.com/aevula/pipelined/tree/master
33
+ changelog_uri: https://github.com/aevula/pipelined/tree/master/CHANGELOG.md
34
+ rubygems_mfa_required: 'true'
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '3.0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubygems_version: 3.3.27
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Gem for building pipelined code flow
54
+ test_files: []