Skip to content

Commit

Permalink
No longer use refinements with Rack::Request
Browse files Browse the repository at this point in the history
  • Loading branch information
lsegal committed Apr 9, 2023
1 parent 7df2a78 commit cf6e530
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# main

- Fix issue with custom Rack::Request attributes in `yard server`

# 0.9.31 - April 9th, 2023

[0.9.31]: https://github.com/lsegal/yard/compare/v0.9.30...v0.9.31
Expand Down
18 changes: 7 additions & 11 deletions lib/yard/server/rack_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ module Server
RackServer = Rack::Server
end

# Safely use refinements since Rack requires 2.4+
# @private
module RackRefinements
refine Rack::Request do
attr_accessor :version_supplied
alias query params
def xhr?; (env['HTTP_X_REQUESTED_WITH'] || "").casecmp("xmlhttprequest") == 0 end
end
end

# This class wraps the {RackAdapter} into a Rack-compatible middleware.
# See {#initialize} for a list of options to pass via Rack's +#use+ method.
#
Expand Down Expand Up @@ -61,7 +51,6 @@ def call(env)
# A server adapter to respond to requests using the Rack server infrastructure.
class RackAdapter < Adapter
include YARD::Server::HTTPUtils
using RackRefinements

# Responds to Rack requests and builds a response with the {Router}.
# @return [Array(Numeric,Hash,Array)] the Rack-style response
Expand Down Expand Up @@ -99,3 +88,10 @@ def print_start_message(server)
end
end
end

# @private
class Rack::Request
attr_accessor :version_supplied
alias query params
def xhr?; (env['HTTP_X_REQUESTED_WITH'] || "").casecmp("xmlhttprequest") == 0 end
end

0 comments on commit cf6e530

Please sign in to comment.