ibsciss-middleware 0.4.2 → 0.4.3

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
- SHA1:
3
- metadata.gz: 95c0eb4642aeaec6b97dc52005fa57572acb48ee
4
- data.tar.gz: 1d1bccc64c0398f96a21bb42f14517fb9bf89ff8
2
+ SHA256:
3
+ metadata.gz: c89cc2b115c1a80b0832be442efcae80215ae469f4c1afadd05e471d3eabc4ca
4
+ data.tar.gz: 3234dc5748481f4e47ce2720818a32e4ef7226e1b052b8caa6c4e8427a0a2da5
5
5
  SHA512:
6
- metadata.gz: 24b5b1b08386e3e5a70d8a8f08d0ce888756105adc43f3d0bee08865e04f07f34141c94a321bd78e44e8f521b260c70eb4ccf2b22218cf00c6f30f94c5f40d32
7
- data.tar.gz: 2a0258cd8b3d3e2a313cdd8e1f9be9549071a864781abf760c63a676316ce7146f694c5a0391f745403ac95d899070fa8af73b58ce29647abc4de79e0d7c8637
6
+ metadata.gz: df9e7568674925a87a0ce50d335d99d6bc351a6536a21d8f044651b74e3c6670190b995a7ad0a5b5b85576eddbb11665186ed445c1cf77769b7d574694959047
7
+ data.tar.gz: a5f4d6137d5a20ede4def20a64c1016560d9dc6964ab0a875343d9e0eb3b948f5c3c4ce839cec9284b26e0fc8f7b658a489a60ac312e4928279398703be5bd8b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.4.3
2
+ - Fix Ruby 3 error when keyword argument is passed
3
+ -
1
4
  ## 0.4.2
2
5
  - Update documentation
3
6
  - Fix bug https://github.com/Ibsciss/ruby-middleware/issues/8
@@ -73,12 +73,12 @@ module Middleware
73
73
  # of the middleware.
74
74
  #
75
75
  # @param [Class] middleware The middleware class
76
- def use(middleware, *args, &block)
76
+ def use(middleware, *args, **kwargs, &block)
77
77
  if middleware.is_a?(Builder)
78
78
  # Merge in the other builder's stack into our own
79
79
  stack.concat(middleware.stack)
80
80
  else
81
- stack << [middleware, args, block]
81
+ stack << [middleware, args, kwargs, block]
82
82
  end
83
83
 
84
84
  self
@@ -42,17 +42,18 @@ module Middleware
42
42
  # is always the empty middleware, which does nothing but return.
43
43
  stack.reverse.inject(EMPTY_MIDDLEWARE) do |next_middleware, current_middleware|
44
44
  # Unpack the actual item
45
- klass, args, block = current_middleware
45
+ klass, args, kwargs, block = current_middleware
46
46
 
47
47
  # Default the arguments to an empty array. Otherwise in Ruby 1.8
48
48
  # a `nil` args will actually pass `nil` into the class. Not what
49
49
  # we want!
50
50
  args ||= []
51
+ kwargs ||= {}
51
52
 
52
53
  if klass.is_a?(Class)
53
54
  # If the klass actually is a class, then instantiate it with
54
55
  # the app and any other arguments given.
55
- klass.new(next_middleware, *args, &block)
56
+ klass.new(next_middleware, *args, **kwargs, &block)
56
57
  elsif klass.respond_to?(:call)
57
58
  # Make it a lambda which calls the item then forwards up
58
59
  # the chain.
data/middleware.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
8
8
  gem.homepage = 'https://github.com/ibsciss/ruby-middleware'
9
9
  gem.license = 'MIT'
10
10
 
11
- gem.add_development_dependency 'rake', '~> 10.4.2'
11
+ gem.add_development_dependency 'rake', '>= 12.3.3'
12
12
  gem.add_development_dependency 'rspec-core', '~> 3.2'
13
13
  gem.add_development_dependency 'rspec-expectations', '~> 3.2'
14
14
  gem.add_development_dependency 'rspec-mocks', '~> 3.2'
@@ -19,5 +19,5 @@ Gem::Specification.new do |gem|
19
19
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
20
  gem.name = 'ibsciss-middleware'
21
21
  gem.require_paths = ['lib']
22
- gem.version = '0.4.2'
22
+ gem.version = '0.4.3'
23
23
  end
@@ -4,6 +4,20 @@ describe Middleware::Builder do
4
4
  let(:data) { { data: [] } }
5
5
  let(:instance) { described_class.new }
6
6
 
7
+ class Foo
8
+ def initialize app, pos, key:
9
+ @app = app
10
+ @pos = pos
11
+ @key = key
12
+ end
13
+
14
+ def call env
15
+ env[:pos] = @pos
16
+ env[:key] = @key
17
+ @app.call(env)
18
+ end
19
+ end
20
+
7
21
  # This returns a proc that can be used with the builder
8
22
  # that simply appends data to an array in the env.
9
23
  def appender_proc(data)
@@ -53,6 +67,16 @@ describe Middleware::Builder do
53
67
  expect(data[:data]).to eq true
54
68
  end
55
69
 
70
+ it 'handles positional and keyword arguments' do
71
+ data = {}
72
+
73
+ instance.use Foo, 1, key: 2
74
+ instance.call(data)
75
+
76
+ expect(data[:pos]).to eq 1
77
+ expect(data[:key]).to eq 2
78
+ end
79
+
56
80
  it 'is able to add multiple items' do
57
81
  data = {}
58
82
  proc1 = ->(env) { env.tap { |obj| obj[:one] = :value_1 } }
@@ -239,4 +263,4 @@ describe Middleware::Builder do
239
263
  end
240
264
  end
241
265
 
242
- end
266
+ end
@@ -85,6 +85,27 @@ describe Middleware::Runner do
85
85
  expect(env[:result]).to eq 42
86
86
  end
87
87
 
88
+ it 'passes in keyword arguments if given' do
89
+ a = Class.new do
90
+ def initialize(_app, foo = nil, bar: nil)
91
+ @foo = foo
92
+ @bar = bar
93
+ end
94
+
95
+ def call(env)
96
+ env[:foo] = @foo
97
+ env[:bar] = @bar
98
+ end
99
+ end
100
+
101
+ env = {}
102
+ instance = described_class.new([[a, [42], { bar: 1764 }, nil]])
103
+ instance.call(env)
104
+
105
+ expect(env[:foo]).to eq 42
106
+ expect(env[:bar]).to eq 1764
107
+ end
108
+
88
109
  it 'passes in a block if given' do
89
110
  a = Class.new do
90
111
  def initialize(_app, &block)
@@ -98,7 +119,7 @@ describe Middleware::Runner do
98
119
 
99
120
  block = proc { 42 }
100
121
  env = {}
101
- instance = described_class.new([[a, nil, block]])
122
+ instance = described_class.new([[a, [], {}, block]])
102
123
  instance.call(env)
103
124
 
104
125
  expect(env[:result]).to eq 42
metadata CHANGED
@@ -1,30 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibsciss-middleware
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitchell Hashimoto
8
8
  - Arnaud Lemaire
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-07-03 00:00:00.000000000 Z
12
+ date: 2024-04-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 10.4.2
20
+ version: 12.3.3
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 10.4.2
27
+ version: 12.3.3
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rspec-core
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +109,7 @@ homepage: https://github.com/ibsciss/ruby-middleware
109
109
  licenses:
110
110
  - MIT
111
111
  metadata: {}
112
- post_install_message:
112
+ post_install_message:
113
113
  rdoc_options: []
114
114
  require_paths:
115
115
  - lib
@@ -124,9 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  requirements: []
127
- rubyforge_project:
128
- rubygems_version: 2.4.3
129
- signing_key:
127
+ rubygems_version: 3.5.5
128
+ signing_key:
130
129
  specification_version: 4
131
130
  summary: Generalized implementation of the rack middleware abstraction for Ruby (chain
132
131
  of responsibility design pattern).