Skip to content

Commit

Permalink
Add support for generic parse_file. (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix authored Apr 3, 2024
1 parent ec318a6 commit d92266f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/protocol/rack/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def self.new(app)
def self.make_response(env, response)
IMPLEMENTATION.make_response(env, response)
end

def self.parse_file(...)
IMPLEMENTATION.parse_file(...)
end
end
end
end
5 changes: 5 additions & 0 deletions lib/protocol/rack/adapter/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ def self.wrap(app)
self.new(app)
end

def self.parse_file(...)
# This is the old interface, which was changed in Rack 3.
::Rack::Builder.parse_file(...).first
end

# Initialize the rack adaptor middleware.
# @parameter app [Object] The rack middleware.
def initialize(app)
Expand Down
4 changes: 4 additions & 0 deletions lib/protocol/rack/adapter/rack3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def self.wrap(app)
self.new(app)
end

def self.parse_file(...)
::Rack::Builder.parse_file(...)
end

def make_environment(request)
request_path, query_string = request.path.split('?', 2)
server_name, server_port = (request.authority || '').split(':', 2)
Expand Down
4 changes: 4 additions & 0 deletions test/protocol/rack/.adapter/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

run lambda {|env|
[200, {}, ["Hello World!"]]
}
8 changes: 8 additions & 0 deletions test/protocol/rack/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
require 'disable_console_context'
require 'server_context'

describe Protocol::Rack::Adapter do
let(:rackup_path) {File.expand_path(".adapter/config.ru", __dir__)}

it "can load rackup files" do
expect(subject.parse_file(rackup_path)).to be_a(Proc)
end
end

describe Protocol::Rack::Adapter::Generic do
let(:adapter) {subject.new(lambda{})}

Expand Down

0 comments on commit d92266f

Please sign in to comment.