From 9ca4839a1aa369d934f08c9307196db3e19e9592 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 22 May 2014 15:57:24 -0700 Subject: [PATCH] stop using PARAMETERS_KEY, and use the accessor on the request object this decouples our code from the env hash a bit. --- actionpack/lib/action_dispatch/journey/router.rb | 12 ++++++------ actionpack/lib/action_dispatch/routing/route_set.rb | 1 - actionpack/test/dispatch/routing_test.rb | 3 +++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/actionpack/lib/action_dispatch/journey/router.rb b/actionpack/lib/action_dispatch/journey/router.rb index ca82d1ff1a..c34b44409e 100644 --- a/actionpack/lib/action_dispatch/journey/router.rb +++ b/actionpack/lib/action_dispatch/journey/router.rb @@ -22,8 +22,10 @@ module ActionDispatch class NullReq # :nodoc: attr_reader :env + attr_accessor :path_parameters def initialize(env) @env = env + @path_parameters = {} end def request_method @@ -48,7 +50,6 @@ module ActionDispatch def initialize(routes, options) @options = options - @params_key = options[:parameters_key] @request_class = options[:request_class] || NullReq @routes = routes end @@ -59,23 +60,22 @@ module ActionDispatch req = request_class.new(env) find_routes(env, req).each do |match, parameters, route| - script_name, path_info, set_params = env.values_at('SCRIPT_NAME', - 'PATH_INFO', - @params_key) + set_params = req.path_parameters + script_name, path_info = env.values_at('SCRIPT_NAME', 'PATH_INFO') unless route.path.anchored env['SCRIPT_NAME'] = (script_name.to_s + match.to_s).chomp('/') env['PATH_INFO'] = match.post_match end - env[@params_key] = (set_params || {}).merge parameters + req.path_parameters = set_params.merge parameters status, headers, body = route.app.call(env) if 'pass' == headers['X-Cascade'] env['SCRIPT_NAME'] = script_name env['PATH_INFO'] = path_info - env[@params_key] = set_params + req.path_parameters = set_params next end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index e82957d824..8b4fd26ce2 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -303,7 +303,6 @@ module ActionDispatch @set = Journey::Routes.new @router = Journey::Router.new(@set, { - :parameters_key => PARAMETERS_KEY, :request_class => request_class}) @formatter = Journey::Formatter.new @set end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 835abc1c7a..051431ce26 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -3368,7 +3368,10 @@ end class TestAltApp < ActionDispatch::IntegrationTest class AltRequest + attr_accessor :path_parameters + def initialize(env) + @path_parameters = {} @env = env end