Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b5ea25bc
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b5ea25bc
编写于
5月 29, 2014
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pass the parsed parameters through the methods so we don't reparse or
require caching code
上级
295e9122
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
34 addition
and
38 deletion
+34
-38
actionpack/lib/action_dispatch/routing/mapper.rb
actionpack/lib/action_dispatch/routing/mapper.rb
+34
-38
未找到文件。
actionpack/lib/action_dispatch/routing/mapper.rb
浏览文件 @
b5ea25bc
...
...
@@ -76,10 +76,11 @@ def initialize(set, scope, path, options)
@default_controller
=
options
[
:controller
]
||
scope
[
:controller
]
@default_action
=
options
[
:action
]
||
scope
[
:action
]
@options
=
normalize_options!
(
options
)
normalize_path!
normalize_requirements!
normalize_conditions!
@path
=
normalize_path!
@path
,
options
[
:format
]
path_params
=
path_params
@path
@options
=
normalize_options!
(
options
,
path_params
)
normalize_requirements!
(
path_params
)
normalize_conditions!
(
path_params
)
normalize_defaults!
end
...
...
@@ -89,26 +90,24 @@ def to_route
private
def
normalize_path!
raise
ArgumentError
,
"path is required"
if
@
path
.
blank?
@path
=
Mapper
.
normalize_path
(
@
path
)
def
normalize_path!
(
path
,
format
)
raise
ArgumentError
,
"path is required"
if
path
.
blank?
path
=
Mapper
.
normalize_path
(
path
)
if
required_format?
@path
=
"
#{
@path
}
.:format"
elsif
optional_format?
@path
=
"
#{
@path
}
(.:format)"
if
format
==
true
"
#{
path
}
.:format"
elsif
optional_format?
(
path
,
format
)
"
#{
path
}
(.:format)"
else
path
end
end
def
required_format?
options
[
:format
]
==
true
end
def
optional_format?
options
[
:format
]
!=
false
&&
!
path
.
include?
(
':format'
)
&&
!
path
.
end_with?
(
'/'
)
def
optional_format?
(
path
,
format
)
format
!=
false
&&
!
path
.
include?
(
':format'
)
&&
!
path
.
end_with?
(
'/'
)
end
def
normalize_options!
(
options
)
def
normalize_options!
(
options
,
path_params
)
path_without_format
=
path
.
sub
(
/\(\.:format\)$/
,
''
)
# Add a constraint for wildcard route to make it non-greedy and match the
...
...
@@ -117,7 +116,7 @@ def normalize_options!(options)
options
[
$1
.
to_sym
]
||=
/.+?/
end
if
path_pa
ttern
.
names
.
map
(
&
:to_sym
)
.
include?
(
:controller
)
if
path_pa
rams
.
include?
(
:controller
)
raise
ArgumentError
,
":controller segment is not allowed within a namespace block"
if
scope
[
:module
]
# Add a default constraint for :controller path segments that matches namespaced
...
...
@@ -130,13 +129,13 @@ def normalize_options!(options)
if
to
.
respond_to?
:call
options
else
options
.
merge!
(
default_controller_and_action
)
options
.
merge!
(
default_controller_and_action
(
path_params
)
)
end
end
def
normalize_requirements!
def
normalize_requirements!
(
path_params
)
constraints
.
each
do
|
key
,
requirement
|
next
unless
segment_key
s
.
include?
(
key
)
||
key
==
:controller
next
unless
path_param
s
.
include?
(
key
)
||
key
==
:controller
verify_regexp_requirement
(
requirement
)
if
requirement
.
is_a?
(
Regexp
)
@requirements
[
key
]
=
requirement
end
...
...
@@ -193,18 +192,18 @@ def verify_callable_constraint(callable_constraint)
end
end
def
normalize_conditions!
def
normalize_conditions!
(
path_params
)
@conditions
[
:path_info
]
=
path
constraints
.
each
do
|
key
,
condition
|
unless
segment_key
s
.
include?
(
key
)
||
key
==
:controller
unless
path_param
s
.
include?
(
key
)
||
key
==
:controller
@conditions
[
key
]
=
condition
end
end
required_defaults
=
[]
options
.
each
do
|
key
,
required_default
|
unless
segment_key
s
.
include?
(
key
)
||
IGNORE_OPTIONS
.
include?
(
key
)
||
Regexp
===
required_default
unless
path_param
s
.
include?
(
key
)
||
IGNORE_OPTIONS
.
include?
(
key
)
||
Regexp
===
required_default
required_defaults
<<
key
end
end
...
...
@@ -240,14 +239,14 @@ def app
end
end
def
default_controller_and_action
def
default_controller_and_action
(
path_params
)
controller
,
action
=
get_controller_and_action
(
default_controller
,
default_action
,
to
,
@scope
[
:module
]
)
hash
=
check_part
(
:controller
,
controller
,
{})
do
|
part
|
hash
=
check_part
(
:controller
,
controller
,
path_params
,
{})
do
|
part
|
translate_controller
(
part
)
{
message
=
"'
#{
part
}
' is not a supported controller name. This can lead to potential routing problems."
message
<<
" See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use"
...
...
@@ -256,16 +255,16 @@ def default_controller_and_action
}
end
check_part
(
:action
,
action
,
hash
)
{
|
part
|
check_part
(
:action
,
action
,
path_params
,
hash
)
{
|
part
|
part
.
is_a?
(
Regexp
)
?
part
:
part
.
to_s
}
end
def
check_part
(
name
,
part
,
hash
)
def
check_part
(
name
,
part
,
path_params
,
hash
)
if
part
hash
[
name
]
=
yield
(
part
)
else
unless
segment_key
s
.
include?
(
name
)
unless
path_param
s
.
include?
(
name
)
message
=
"Missing :
#{
name
}
key on routes definition, please check your routes."
raise
ArgumentError
,
message
end
...
...
@@ -317,16 +316,13 @@ def constraints
end
end
def
segment_keys
@segment_keys
||=
path_pattern
.
names
.
map
{
|
s
|
s
.
to_sym
}
end
def
path_pattern
Journey
::
Path
::
Pattern
.
new
(
strexp
)
def
path_params
(
path
)
path_ast
(
path
).
grep
(
Journey
::
Nodes
::
Symbol
).
map
{
|
n
|
n
.
name
.
to_sym
}
end
def
strexp
Journey
::
Router
::
Strexp
.
compile
(
path
,
requirements
,
SEPARATORS
)
def
path_ast
(
path
)
parser
=
Journey
::
Parser
.
new
parser
.
parse
path
end
def
dispatcher
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录