提交 2ffa126f 编写于 作者: A Aaron Patterson

PARAMETERS_KEY is only used in the request, so move the constant there

上级 cfdab77d
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
module ActionDispatch module ActionDispatch
module Http module Http
module Parameters module Parameters
PARAMETERS_KEY = 'action_dispatch.request.path_parameters'
def initialize(env) def initialize(env)
super super
@symbolized_path_params = nil @symbolized_path_params = nil
...@@ -25,7 +27,7 @@ def parameters ...@@ -25,7 +27,7 @@ def parameters
def path_parameters=(parameters) #:nodoc: def path_parameters=(parameters) #:nodoc:
@env.delete('action_dispatch.request.parameters') @env.delete('action_dispatch.request.parameters')
@env[Routing::RouteSet::PARAMETERS_KEY] = parameters @env[PARAMETERS_KEY] = parameters
end end
# The same as <tt>path_parameters</tt> with explicitly symbolized keys. # The same as <tt>path_parameters</tt> with explicitly symbolized keys.
...@@ -40,7 +42,7 @@ def symbolized_path_parameters ...@@ -40,7 +42,7 @@ def symbolized_path_parameters
# #
# See <tt>symbolized_path_parameters</tt> for symbolized keys. # See <tt>symbolized_path_parameters</tt> for symbolized keys.
def path_parameters def path_parameters
@env[Routing::RouteSet::PARAMETERS_KEY] ||= {} @env[PARAMETERS_KEY] ||= {}
end end
private private
......
...@@ -19,8 +19,6 @@ class RouteSet #:nodoc: ...@@ -19,8 +19,6 @@ class RouteSet #:nodoc:
# alias inspect to to_s. # alias inspect to to_s.
alias inspect to_s alias inspect to_s
PARAMETERS_KEY = 'action_dispatch.request.path_parameters'
class Dispatcher < Routing::Endpoint #:nodoc: class Dispatcher < Routing::Endpoint #:nodoc:
def initialize(defaults) def initialize(defaults)
@defaults = defaults @defaults = defaults
......
...@@ -87,7 +87,7 @@ def setup ...@@ -87,7 +87,7 @@ def setup
def test_symbols_with_dashes def test_symbols_with_dashes
rs.draw do rs.draw do
get '/:artist/:song-omg', :to => lambda { |env| get '/:artist/:song-omg', :to => lambda { |env|
resp = ActiveSupport::JSON.encode env[ActionDispatch::Routing::RouteSet::PARAMETERS_KEY] resp = ActiveSupport::JSON.encode ActionDispatch::Request.new(env).path_parameters
[200, {}, [resp]] [200, {}, [resp]]
} }
end end
...@@ -99,7 +99,7 @@ def test_symbols_with_dashes ...@@ -99,7 +99,7 @@ def test_symbols_with_dashes
def test_id_with_dash def test_id_with_dash
rs.draw do rs.draw do
get '/journey/:id', :to => lambda { |env| get '/journey/:id', :to => lambda { |env|
resp = ActiveSupport::JSON.encode env[ActionDispatch::Routing::RouteSet::PARAMETERS_KEY] resp = ActiveSupport::JSON.encode ActionDispatch::Request.new(env).path_parameters
[200, {}, [resp]] [200, {}, [resp]]
} }
end end
...@@ -111,7 +111,7 @@ def test_id_with_dash ...@@ -111,7 +111,7 @@ def test_id_with_dash
def test_dash_with_custom_regexp def test_dash_with_custom_regexp
rs.draw do rs.draw do
get '/:artist/:song-omg', :constraints => { :song => /\d+/ }, :to => lambda { |env| get '/:artist/:song-omg', :constraints => { :song => /\d+/ }, :to => lambda { |env|
resp = ActiveSupport::JSON.encode env[ActionDispatch::Routing::RouteSet::PARAMETERS_KEY] resp = ActiveSupport::JSON.encode ActionDispatch::Request.new(env).path_parameters
[200, {}, [resp]] [200, {}, [resp]]
} }
end end
...@@ -124,7 +124,7 @@ def test_dash_with_custom_regexp ...@@ -124,7 +124,7 @@ def test_dash_with_custom_regexp
def test_pre_dash def test_pre_dash
rs.draw do rs.draw do
get '/:artist/omg-:song', :to => lambda { |env| get '/:artist/omg-:song', :to => lambda { |env|
resp = ActiveSupport::JSON.encode env[ActionDispatch::Routing::RouteSet::PARAMETERS_KEY] resp = ActiveSupport::JSON.encode ActionDispatch::Request.new(env).path_parameters
[200, {}, [resp]] [200, {}, [resp]]
} }
end end
...@@ -136,7 +136,7 @@ def test_pre_dash ...@@ -136,7 +136,7 @@ def test_pre_dash
def test_pre_dash_with_custom_regexp def test_pre_dash_with_custom_regexp
rs.draw do rs.draw do
get '/:artist/omg-:song', :constraints => { :song => /\d+/ }, :to => lambda { |env| get '/:artist/omg-:song', :constraints => { :song => /\d+/ }, :to => lambda { |env|
resp = ActiveSupport::JSON.encode env[ActionDispatch::Routing::RouteSet::PARAMETERS_KEY] resp = ActiveSupport::JSON.encode ActionDispatch::Request.new(env).path_parameters
[200, {}, [resp]] [200, {}, [resp]]
} }
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册