meddleware 0.3.0 → 0.4.0

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: '0197bd468d02ee66541d9ae7b369afc2ad0632cb6058cc3d8856a2b87f8ff897'
4
- data.tar.gz: 4dab2733ff8907db8abbe3b3b11d45ba536d2bc76831d7128b68a4db5847900e
3
+ metadata.gz: 0c9a407cd470f194fda6286e743513706d094408be53bd75a31ebd14eef97fa2
4
+ data.tar.gz: 57243177c0047d94f58ca39eb3f9ceb6b9cdcb37aa204be3f2c511a934905e68
5
5
  SHA512:
6
- metadata.gz: 305a9da953ca540f424296aca10836829cff777c39698b1938f998f7f425045cd3fb69fef9563a34579858e87b8fd38d02971a7fc72b1ef34df3b242f80d18f2
7
- data.tar.gz: '08023838c15da52c5339ad7efeb6124eea151aa8d4ea334dd15b01f64c191ae8f4d4eaf01e7f9171a10606c368aa70a87c30ac297792d7c2e443dec575820b81'
6
+ metadata.gz: 52816fdea29cea1af9a32ce346079686fe75ced2ac34d4bf972afe174e7d74a7bd62cd1e0bac6aab6433eb3373c66772d373ed17778ee251857625e1d7368fde
7
+ data.tar.gz: e4eb77b1748be5c025b3be3bf3c049ed167e7cd7624deb1ef980542667b4eb556a60c40ee911ac805f2aaa7de01a0c199129f45edc3b6701dd589bb23130434f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### v0.4.0 (2024-04-05)
2
+ - drop ruby 2.7
3
+ - gem constraints
4
+ - simplify codecov
5
+ - drop rake
6
+ - test coverage
7
+
1
8
  ### v0.3.0 (2022-10-11)
2
9
  - extendable
3
10
  - drop ruby 2.5 (#4)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ meddleware (0.3.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ byebug (11.1.3)
10
+ diff-lcs (1.5.1)
11
+ docile (1.4.0)
12
+ rspec (3.13.0)
13
+ rspec-core (~> 3.13.0)
14
+ rspec-expectations (~> 3.13.0)
15
+ rspec-mocks (~> 3.13.0)
16
+ rspec-core (3.13.0)
17
+ rspec-support (~> 3.13.0)
18
+ rspec-expectations (3.13.0)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.13.0)
21
+ rspec-mocks (3.13.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.13.0)
24
+ rspec-support (3.13.1)
25
+ simplecov (0.22.0)
26
+ docile (~> 1.1)
27
+ simplecov-html (~> 0.11)
28
+ simplecov_json_formatter (~> 0.1)
29
+ simplecov-html (0.12.3)
30
+ simplecov_json_formatter (0.1.4)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ byebug (>= 11)
37
+ meddleware!
38
+ rspec (>= 3.13)
39
+ simplecov (>= 0.22)
40
+
41
+ BUNDLED WITH
42
+ 2.5.7
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  Meddleware
2
2
  ======
3
+ ![Gem](https://img.shields.io/gem/dt/meddleware?style=plastic)
4
+ [![codecov](https://codecov.io/gh/dpep/meddleware_rb/branch/main/graph/badge.svg)](https://codecov.io/gh/dpep/meddleware_rb)
5
+
6
+
3
7
  A middleware framework to make meddling easy. Middleware is a popular pattern from Rack and Rails, which provides callers a way to execute code before and after yours. This gives callers the ability to modify parameters or results, conditionally skip execution, and log activity without the need to monkey patch or subclass.
4
8
 
5
9
 
@@ -139,8 +143,3 @@ Yes please :)
139
143
  [@mperham](https://github.com/mperham) + [Sidekiq](https://github.com/mperham/sidekiq/blob/master/lib/sidekiq/middleware/chain.rb)
140
144
 
141
145
  [Rails](https://github.com/rails/rails/blob/main/actionpack/lib/action_dispatch/middleware/stack.rb)
142
-
143
-
144
- ----
145
- ![Gem](https://img.shields.io/gem/dt/meddleware?style=plastic)
146
- [![codecov](https://codecov.io/gh/dpep/meddleware_rb/branch/main/graph/badge.svg)](https://codecov.io/gh/dpep/meddleware_rb)
@@ -183,10 +183,5 @@ module Meddleware
183
183
  end
184
184
  end
185
185
  end
186
-
187
- if RUBY_VERSION < '3'
188
- require 'meddleware/v2_7'
189
- prepend Meddleware::V2_7
190
- end
191
186
  end
192
187
  end
@@ -1,3 +1,3 @@
1
1
  module Meddleware
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/meddleware.gemspec CHANGED
@@ -1,29 +1,19 @@
1
- package_name = File.basename(__FILE__).split(".")[0]
2
- load Dir.glob("lib/**/version.rb")[0]
3
-
1
+ require_relative "lib/meddleware/version"
4
2
  package = Meddleware
5
3
 
6
-
7
4
  Gem::Specification.new do |s|
8
- s.name = package_name
5
+ s.name = File.basename(__FILE__).split(".")[0]
9
6
  s.version = package.const_get 'VERSION'
10
7
  s.authors = ['Daniel Pepper']
11
8
  s.summary = package.to_s
12
9
  s.description = 'A middleware framework to make meddling easy.'
13
- s.homepage = "https://github.com/dpep/#{package_name}_rb"
10
+ s.homepage = "https://github.com/dpep/meddleware_rb"
14
11
  s.license = 'MIT'
15
- s.required_ruby_version = '>= 2.7'
12
+ s.files = `git ls-files * ':!:spec'`.split("\n")
16
13
 
17
- s.files = Dir[
18
- __FILE__,
19
- 'lib/**/*',
20
- 'CHANGELOG*',
21
- 'LICENSE*',
22
- 'README*',
23
- ]
14
+ s.required_ruby_version = '>= 3'
24
15
 
25
- s.add_development_dependency 'byebug'
26
- s.add_development_dependency 'codecov'
27
- s.add_development_dependency 'rspec'
28
- s.add_development_dependency 'simplecov'
16
+ s.add_development_dependency 'byebug', '>= 11'
17
+ s.add_development_dependency 'rspec', '>= 3.13'
18
+ s.add_development_dependency 'simplecov', '>= 0.22'
29
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meddleware
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Pepper
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-11 00:00:00.000000000 Z
11
+ date: 2024-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -16,75 +16,62 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '11'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: codecov
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: '11'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - ">="
46
32
  - !ruby/object:Gem::Version
47
- version: '0'
33
+ version: '3.13'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - ">="
53
39
  - !ruby/object:Gem::Version
54
- version: '0'
40
+ version: '3.13'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: simplecov
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - ">="
60
46
  - !ruby/object:Gem::Version
61
- version: '0'
47
+ version: '0.22'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - ">="
67
53
  - !ruby/object:Gem::Version
68
- version: '0'
54
+ version: '0.22'
69
55
  description: A middleware framework to make meddling easy.
70
- email:
56
+ email:
71
57
  executables: []
72
58
  extensions: []
73
59
  extra_rdoc_files: []
74
60
  files:
75
61
  - CHANGELOG.md
62
+ - Gemfile
63
+ - Gemfile.lock
76
64
  - LICENSE.txt
77
65
  - README.md
78
66
  - lib/meddleware.rb
79
67
  - lib/meddleware/stack.rb
80
- - lib/meddleware/v2_7.rb
81
68
  - lib/meddleware/version.rb
82
69
  - meddleware.gemspec
83
70
  homepage: https://github.com/dpep/meddleware_rb
84
71
  licenses:
85
72
  - MIT
86
73
  metadata: {}
87
- post_install_message:
74
+ post_install_message:
88
75
  rdoc_options: []
89
76
  require_paths:
90
77
  - lib
@@ -92,15 +79,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
79
  requirements:
93
80
  - - ">="
94
81
  - !ruby/object:Gem::Version
95
- version: '2.7'
82
+ version: '3'
96
83
  required_rubygems_version: !ruby/object:Gem::Requirement
97
84
  requirements:
98
85
  - - ">="
99
86
  - !ruby/object:Gem::Version
100
87
  version: '0'
101
88
  requirements: []
102
- rubygems_version: 3.1.6
103
- signing_key:
89
+ rubygems_version: 3.0.3.1
90
+ signing_key:
104
91
  specification_version: 4
105
- summary: Gem::Specification::Meddleware
92
+ summary: Meddleware
106
93
  test_files: []
@@ -1,143 +0,0 @@
1
- # backwards compatible functionality for Ruby 2.7
2
-
3
- module Meddleware
4
- module V2_7
5
- def use(*klass_and_args, &block)
6
- entry = create_entry(klass_and_args, block)
7
- remove(entry[0])
8
- stack << entry
9
- self
10
- end
11
- alias append use
12
-
13
- def prepend(*klass_and_args, &block)
14
- entry = create_entry(klass_and_args, block)
15
- remove(entry[0])
16
- stack.insert(0, entry)
17
- self
18
- end
19
-
20
- def after(after_klass, *klass_and_args, &block)
21
- entry = create_entry(klass_and_args, block)
22
- remove(entry[0])
23
-
24
- i = if after_klass.is_a? Array
25
- after_klass.map {|x| index(x) }.compact.max
26
- else
27
- index(after_klass)
28
- end
29
- i ||= count - 1 # last element
30
-
31
- stack.insert(i + 1, entry)
32
- self
33
- end
34
-
35
- def before(before_klass, *klass_and_args, &block)
36
- entry = create_entry(klass_and_args, block)
37
- remove(entry[0])
38
-
39
- i = if before_klass.is_a? Array
40
- before_klass.map {|x| index(x) }.compact.min
41
- else
42
- index(before_klass)
43
- end
44
- i ||= 0 # first element
45
-
46
- stack.insert(i, entry)
47
- self
48
- end
49
-
50
- def replace(old_klass, *klass_and_args, &block)
51
- entry = create_entry(klass_and_args, block)
52
- remove(entry[0])
53
-
54
- i = index(old_klass)
55
-
56
- unless i
57
- raise RuntimeError, "middleware not present: #{old_klass}"
58
- end
59
-
60
- stack[i] = entry
61
- self
62
- end
63
-
64
- def call(*args)
65
- chain = build_chain
66
- default_args = args
67
-
68
- traverse = proc do |*args|
69
- if args.empty?
70
- args = default_args
71
- else
72
- default_args = args
73
- end
74
-
75
- if chain.empty?
76
- yield(*args) if block_given?
77
- else
78
- middleware = chain.shift
79
-
80
- if middleware.is_a?(Proc) && !middleware.lambda?
81
- middleware.call(*args)
82
-
83
- # implicit yield
84
- traverse.call(*args)
85
- else
86
- middleware.call(*args, &traverse)
87
- end
88
- end
89
- end
90
- traverse.call(*args)
91
- end
92
-
93
-
94
- private
95
-
96
- def create_entry(klass_and_args, block)
97
- klass, *args = klass_and_args
98
-
99
- if [ klass, block ].compact.count == 0
100
- raise ArgumentError, 'either a middleware or block must be provided'
101
- end
102
-
103
- if klass
104
- # validate
105
- if klass.is_a? Class
106
- unless klass.method_defined?(:call)
107
- raise ArgumentError, "middleware must implement `.call`: #{klass}"
108
- end
109
- else
110
- unless klass.respond_to?(:call)
111
- raise ArgumentError, "middleware must respond to `.call`: #{klass}"
112
- end
113
-
114
- unless block.nil?
115
- raise ArgumentError, 'can not supply middleware instance and block'
116
- end
117
- end
118
-
119
- [ klass, args, block ].compact
120
- else
121
- [ block ]
122
- end
123
- end
124
-
125
- def build_chain
126
- # build the middleware stack
127
- stack.map do |klass, args, block|
128
- if klass.is_a? Class
129
- klass.new(*args, &block)
130
- else
131
- if args.nil? || args.empty?
132
- klass
133
- else
134
- # curry args
135
- ->(*more_args, &block) do
136
- klass.call(*args, *more_args, &block)
137
- end
138
- end
139
- end
140
- end
141
- end
142
- end
143
- end