ibsciss-middleware 0.4.1 → 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: 86fc76bf275b9613ba8eaf6234356f6e897e8fa2
4
- data.tar.gz: 40a061815db18be1438ce941abd3d8df47d80c96
2
+ SHA256:
3
+ metadata.gz: c89cc2b115c1a80b0832be442efcae80215ae469f4c1afadd05e471d3eabc4ca
4
+ data.tar.gz: 3234dc5748481f4e47ce2720818a32e4ef7226e1b052b8caa6c4e8427a0a2da5
5
5
  SHA512:
6
- metadata.gz: 20bdeb80623bfad270d6a44d5d7d7c95dc00af9ce262728649ea88b90ae0bb6a1dae6c2cecef187363631fecc8718300e8b5ee6c54d445ffe2b603f0b7d30e57
7
- data.tar.gz: 7cfefa01cc28a9765bb715af5f1513acc8c839c47d241204ebcee26d4be57372b07c3fa74ba8ac4100e0a17218c4d507ab52070af24710ddde7f81c15d98abe2
6
+ metadata.gz: df9e7568674925a87a0ce50d335d99d6bc351a6536a21d8f044651b74e3c6670190b995a7ad0a5b5b85576eddbb11665186ed445c1cf77769b7d574694959047
7
+ data.tar.gz: a5f4d6137d5a20ede4def20a64c1016560d9dc6964ab0a875343d9e0eb3b948f5c3c4ce839cec9284b26e0fc8f7b658a489a60ac312e4928279398703be5bd8b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 0.4.3
2
+ - Fix Ruby 3 error when keyword argument is passed
3
+ -
4
+ ## 0.4.2
5
+ - Update documentation
6
+ - Fix bug https://github.com/Ibsciss/ruby-middleware/issues/8
7
+
8
+ ## 0.4.1
9
+ - Simplify the inspect method
10
+
1
11
  ## 0.4.0
2
12
  - Add a name displayed in the logger & inspect methods
3
13
  - Add a logger middleware
data/README.md CHANGED
@@ -28,7 +28,7 @@ $ gem install ibsciss-middleware
28
28
  Or, in your Gemfile:
29
29
 
30
30
  ```
31
- gem 'ibsciss-middleware', '~> 0.3'
31
+ gem 'ibsciss-middleware', '~> 0.4.2'
32
32
  ```
33
33
 
34
34
  Then, you can add it to your project:
@@ -169,8 +169,8 @@ lambdas:
169
169
 
170
170
  ```ruby
171
171
  Middleware::Builder.new { |b|
172
- b.use lambda { |env| env + 3 }
173
- b.use lambda { |env| env * 2 }
172
+ b.use -> (env) { env + 3 }
173
+ b.use -> (env) { env * 2 }
174
174
  }.call(1) #return 8
175
175
  ```
176
176
 
@@ -188,7 +188,7 @@ for building a stack of middlewares:
188
188
  ```ruby
189
189
  stack = Middleware::Builder.new do |d|
190
190
  d.use Trace
191
- d.use lambda { |env| puts "LAMBDA!" }
191
+ d.use ->(env) { puts "LAMBDA!" }
192
192
  end
193
193
  ```
194
194
 
@@ -241,7 +241,7 @@ stack.insert_after(0, SomeOtherMiddleware)
241
241
  #### Insert after each
242
242
 
243
243
  ```ruby
244
- logger = lambda { |env| p env }
244
+ logger = -> (env) { p env }
245
245
 
246
246
  # Insert the middleware (can be also a middleware object) after each existing middleware
247
247
  stack.insert_after_each logger
@@ -250,7 +250,7 @@ stack.insert_after_each logger
250
250
  #### Insert before each
251
251
 
252
252
  ```ruby
253
- logger = lambda { |env| p env }
253
+ logger = -> (env) { p env }
254
254
 
255
255
  # Insert the middleware (can be also a middleware object) before each existing middleware
256
256
  stack.insert_before_each logger
@@ -73,19 +73,18 @@ 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
85
85
  end
86
86
 
87
- # Inserts a middleware at the given index or directly before the
88
- # given middleware object.
87
+ # Inserts a middleware at the given index or directly before the given middleware object.
89
88
  def insert(index, middleware, *args, &block)
90
89
  index = self.index(index) unless index.is_a?(Integer)
91
90
  fail "no such middleware to insert before: #{index.inspect}" unless index
@@ -115,16 +114,12 @@ module Middleware
115
114
  end
116
115
  end
117
116
 
118
- # Replaces the given middleware object or index with the new
119
- # middleware.
117
+ # Replaces the given middleware object or index with the new middleware.
120
118
  def replace(index, middleware, *args, &block)
121
- if index.is_a?(Integer)
122
- delete(index)
123
- insert(index, middleware, *args, &block)
124
- else
125
- insert_before(index, middleware, *args, &block)
126
- delete(index)
127
- end
119
+ index = self.index index unless index.is_a? Integer
120
+
121
+ delete(index)
122
+ insert(index, middleware, *args, &block)
128
123
  end
129
124
 
130
125
  # Deletes the given middleware object or index
@@ -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.1'
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.1
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: 2015-11-17 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).