mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
stop using PARAMETERS_KEY, and use the accessor on the request object
this decouples our code from the env hash a bit.
This commit is contained in:
parent
1b76c7e9f6
commit
9ca4839a1a
3 changed files with 9 additions and 7 deletions
|
@ -22,8 +22,10 @@ module ActionDispatch
|
||||||
|
|
||||||
class NullReq # :nodoc:
|
class NullReq # :nodoc:
|
||||||
attr_reader :env
|
attr_reader :env
|
||||||
|
attr_accessor :path_parameters
|
||||||
def initialize(env)
|
def initialize(env)
|
||||||
@env = env
|
@env = env
|
||||||
|
@path_parameters = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def request_method
|
def request_method
|
||||||
|
@ -48,7 +50,6 @@ module ActionDispatch
|
||||||
|
|
||||||
def initialize(routes, options)
|
def initialize(routes, options)
|
||||||
@options = options
|
@options = options
|
||||||
@params_key = options[:parameters_key]
|
|
||||||
@request_class = options[:request_class] || NullReq
|
@request_class = options[:request_class] || NullReq
|
||||||
@routes = routes
|
@routes = routes
|
||||||
end
|
end
|
||||||
|
@ -59,23 +60,22 @@ module ActionDispatch
|
||||||
req = request_class.new(env)
|
req = request_class.new(env)
|
||||||
|
|
||||||
find_routes(env, req).each do |match, parameters, route|
|
find_routes(env, req).each do |match, parameters, route|
|
||||||
script_name, path_info, set_params = env.values_at('SCRIPT_NAME',
|
set_params = req.path_parameters
|
||||||
'PATH_INFO',
|
script_name, path_info = env.values_at('SCRIPT_NAME', 'PATH_INFO')
|
||||||
@params_key)
|
|
||||||
|
|
||||||
unless route.path.anchored
|
unless route.path.anchored
|
||||||
env['SCRIPT_NAME'] = (script_name.to_s + match.to_s).chomp('/')
|
env['SCRIPT_NAME'] = (script_name.to_s + match.to_s).chomp('/')
|
||||||
env['PATH_INFO'] = match.post_match
|
env['PATH_INFO'] = match.post_match
|
||||||
end
|
end
|
||||||
|
|
||||||
env[@params_key] = (set_params || {}).merge parameters
|
req.path_parameters = set_params.merge parameters
|
||||||
|
|
||||||
status, headers, body = route.app.call(env)
|
status, headers, body = route.app.call(env)
|
||||||
|
|
||||||
if 'pass' == headers['X-Cascade']
|
if 'pass' == headers['X-Cascade']
|
||||||
env['SCRIPT_NAME'] = script_name
|
env['SCRIPT_NAME'] = script_name
|
||||||
env['PATH_INFO'] = path_info
|
env['PATH_INFO'] = path_info
|
||||||
env[@params_key] = set_params
|
req.path_parameters = set_params
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -303,7 +303,6 @@ module ActionDispatch
|
||||||
|
|
||||||
@set = Journey::Routes.new
|
@set = Journey::Routes.new
|
||||||
@router = Journey::Router.new(@set, {
|
@router = Journey::Router.new(@set, {
|
||||||
:parameters_key => PARAMETERS_KEY,
|
|
||||||
:request_class => request_class})
|
:request_class => request_class})
|
||||||
@formatter = Journey::Formatter.new @set
|
@formatter = Journey::Formatter.new @set
|
||||||
end
|
end
|
||||||
|
|
|
@ -3368,7 +3368,10 @@ end
|
||||||
|
|
||||||
class TestAltApp < ActionDispatch::IntegrationTest
|
class TestAltApp < ActionDispatch::IntegrationTest
|
||||||
class AltRequest
|
class AltRequest
|
||||||
|
attr_accessor :path_parameters
|
||||||
|
|
||||||
def initialize(env)
|
def initialize(env)
|
||||||
|
@path_parameters = {}
|
||||||
@env = env
|
@env = env
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue