Skip to content

Commit cb7852f

Browse files
Drop support for Ruby before 3.0
Use argument forwarding for middleware and delegators instead of ruby2_keywords. Remove obsolete compatibility branches and test only supported Ruby versions. Assisted-By: devx/9a5ced6c-36f2-46e3-a662-1765c7341b0e
1 parent 0463dee commit cb7852f

15 files changed

Lines changed: 108 additions & 113 deletions

.github/workflows/test.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ jobs:
1313
os:
1414
- ubuntu-latest
1515
ruby:
16-
- '2.4'
17-
- '2.5'
18-
- '2.6'
19-
- '2.7'
2016
- '3.0'
2117
- '3.1'
2218
- '3.2'

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ require:
22
- rubocop-packaging
33

44
AllCops:
5-
TargetRubyVersion: 2.4
5+
TargetRubyVersion: 3.0
66
DisabledByDefault: true
77
Exclude:
88
- '**/vendor/**/*'

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ All notable changes to this project will be documented in this file. For info on
2020

2121
### Changed
2222

23+
- Require Ruby 3.0 or newer and replace `ruby2_keywords` with argument forwarding.
2324
- Raise before exceeding a part limit, not after. ([#2362](https://github.com/rack/rack/pull/2362), [@matthew-puku](https://github.com/matthew-puku))
2425
- Rack::Deflater now uses a fixed GZip mtime value. ([#2372](https://github.com/rack/rack/pull/2372), [@bensheldon](https://github.com/bensheldon))
2526
- Multipart parser drops support for RFC 2231 `filename*` parameter (prohibited by RFC 7578) and now properly handles UTF-8 encoded filenames via percent-encoding and direct UTF-8 bytes. ([#2398](https://github.com/rack/rack/pull/2398), [@wtn](https://github.com/wtn))

Gemfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ group :doc do
1515
else
1616
gem "rdoc"
1717
end
18-
19-
gem "psych", "= 3.0.2" if RUBY_VERSION[0..2] == "2.5"
2018
end
2119

2220
group :test do

lib/rack/body_proxy.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,19 @@ def closed?
4242
end
4343

4444
# Delegate missing methods to the wrapped body.
45-
def method_missing(method_name, *args, &block)
45+
def method_missing(method_name, ...)
4646
case method_name
4747
when :to_str
4848
super
4949
when :to_ary
5050
begin
51-
@body.__send__(method_name, *args, &block)
51+
@body.__send__(method_name, ...)
5252
ensure
5353
close
5454
end
5555
else
56-
@body.__send__(method_name, *args, &block)
56+
@body.__send__(method_name, ...)
5757
end
5858
end
59-
# :nocov:
60-
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
61-
# :nocov:
6259
end
6360
end

lib/rack/builder.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,15 @@ def self.app(default_app = nil, &block)
156156
# All requests through to this application will first be processed by the middleware class.
157157
# The +call+ method in this example sets an additional environment key which then can be
158158
# referenced in the application if required.
159-
def use(middleware, *args, &block)
159+
def use(middleware, ...)
160160
if @map
161161
mapping, @map = @map, nil
162162
@use << proc { |app| generate_map(app, mapping) }
163163
end
164-
@use << proc { |app| middleware.new(app, *args, &block) }
164+
@use << proc { |app| middleware.new(app, ...) }
165165

166166
nil
167167
end
168-
# :nocov:
169-
ruby2_keywords(:use) if respond_to?(:ruby2_keywords, true)
170-
# :nocov:
171168

172169
# Takes a block or argument that is an object that responds to #call and
173170
# returns a Rack response.

lib/rack/deflater.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module Rack
2727
# encoding.
2828
class Deflater
2929

30-
GZIP_MTIME = RUBY_VERSION >= "2.7" ? 0 : 1
30+
GZIP_MTIME = 0
3131

3232
# Creates Rack::Deflater middleware. Options:
3333
#

lib/rack/headers.rb

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -199,34 +199,26 @@ def values_at(*keys)
199199
keys.map{|key| self[key]}
200200
end
201201

202-
# :nocov:
203-
if RUBY_VERSION >= '2.5'
204-
# :nocov:
205-
def slice(*a)
206-
h = self.class.new
207-
a.each{|k| h[k] = self[k] if has_key?(k)}
208-
h
209-
end
202+
def slice(*a)
203+
h = self.class.new
204+
a.each{|k| h[k] = self[k] if has_key?(k)}
205+
h
206+
end
210207

211-
def transform_keys(&block)
212-
dup.transform_keys!(&block)
213-
end
208+
def transform_keys(&block)
209+
dup.transform_keys!(&block)
210+
end
214211

215-
def transform_keys!
216-
hash = self.class.new
217-
each do |k, v|
218-
hash[yield k] = v
219-
end
220-
replace(hash)
212+
def transform_keys!
213+
hash = self.class.new
214+
each do |k, v|
215+
hash[yield k] = v
221216
end
217+
replace(hash)
222218
end
223219

224-
# :nocov:
225-
if RUBY_VERSION >= '3.0'
226-
# :nocov:
227-
def except(*a)
228-
super(*a.map!{|key| downcase_key(key)})
229-
end
220+
def except(*a)
221+
super(*a.map!{|key| downcase_key(key)})
230222
end
231223

232224
private

lib/rack/mock_response.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ def initialize(args)
2323
@secure = args["secure"]
2424
end
2525

26-
def method_missing(method_name, *args, &block)
27-
@value.send(method_name, *args, &block)
26+
def method_missing(method_name, ...)
27+
@value.send(method_name, ...)
2828
end
29-
# :nocov:
30-
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
31-
# :nocov:
3229

3330
def respond_to_missing?(method_name, include_all = false)
3431
@value.respond_to?(method_name, include_all) || super

lib/rack/multipart/uploaded_file.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,9 @@ def respond_to_missing?(*args)
7474
end
7575

7676
# Delegate method missing calls to the tempfile.
77-
def method_missing(method_name, *args, &block) #:nodoc:
78-
@tempfile.__send__(method_name, *args, &block)
77+
def method_missing(method_name, ...) #:nodoc:
78+
@tempfile.__send__(method_name, ...)
7979
end
80-
# :nocov:
81-
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
82-
# :nocov:
8380
end
8481
end
8582
end

0 commit comments

Comments
 (0)