Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
cb46e7a7
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,发现更多精彩内容 >>
提交
cb46e7a7
编写于
7月 06, 2012
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6990 from mirceapricop/bug/mime-type-method-name
Fix: Mime type names conflict with Object methods
上级
717aa92d
021f3d24
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
33 addition
and
2 deletion
+33
-2
actionpack/lib/abstract_controller/collector.rb
actionpack/lib/abstract_controller/collector.rb
+4
-0
actionpack/lib/action_dispatch/http/mime_type.rb
actionpack/lib/action_dispatch/http/mime_type.rb
+12
-1
actionpack/test/controller/mime_responds_test.rb
actionpack/test/controller/mime_responds_test.rb
+3
-1
actionpack/test/dispatch/mime_type_test.rb
actionpack/test/dispatch/mime_type_test.rb
+14
-0
未找到文件。
actionpack/lib/abstract_controller/collector.rb
浏览文件 @
cb46e7a7
...
...
@@ -16,6 +16,10 @@ def #{sym}(*args, &block) # def html(*args, &block)
generate_method_for_mime
(
mime
)
end
Mime
::
Type
.
register_callback
do
|
mime
|
generate_method_for_mime
(
mime
)
unless
self
.
instance_methods
.
include?
(
mime
.
to_sym
)
end
protected
def
method_missing
(
symbol
,
&
block
)
...
...
actionpack/lib/action_dispatch/http/mime_type.rb
浏览文件 @
cb46e7a7
...
...
@@ -58,6 +58,8 @@ class Type
cattr_reader
:browser_generated_types
attr_reader
:symbol
@register_callbacks
=
[]
# A simple helper class used in parsing the accept header
class
AcceptItem
#:nodoc:
attr_accessor
:order
,
:name
,
:q
...
...
@@ -89,6 +91,10 @@ class << self
TRAILING_STAR_REGEXP
=
/(text|application)\/\*/
PARAMETER_SEPARATOR_REGEXP
=
/;\s*\w+="?\w+"?/
def
register_callback
(
&
block
)
@register_callbacks
<<
block
end
def
lookup
(
string
)
LOOKUP
[
string
]
end
...
...
@@ -106,10 +112,15 @@ def register_alias(string, symbol, extension_synonyms = [])
def
register
(
string
,
symbol
,
mime_type_synonyms
=
[],
extension_synonyms
=
[],
skip_lookup
=
false
)
Mime
.
const_set
(
symbol
.
upcase
,
Type
.
new
(
string
,
symbol
,
mime_type_synonyms
))
SET
<<
Mime
.
const_get
(
symbol
.
upcase
)
new_mime
=
Mime
.
const_get
(
symbol
.
upcase
)
SET
<<
new_mime
([
string
]
+
mime_type_synonyms
).
each
{
|
str
|
LOOKUP
[
str
]
=
SET
.
last
}
unless
skip_lookup
([
symbol
]
+
extension_synonyms
).
each
{
|
ext
|
EXTENSION_LOOKUP
[
ext
.
to_s
]
=
SET
.
last
}
@register_callbacks
.
each
do
|
callback
|
callback
.
call
(
new_mime
)
end
end
def
parse
(
accept_header
)
...
...
actionpack/test/controller/mime_responds_test.rb
浏览文件 @
cb46e7a7
...
...
@@ -505,7 +505,7 @@ def test_invalid_format
end
class
RespondWithController
<
ActionController
::
Base
respond_to
:html
,
:json
respond_to
:html
,
:json
,
:touch
respond_to
:xml
,
:except
=>
:using_resource_with_block
respond_to
:js
,
:only
=>
[
:using_resource_with_block
,
:using_resource
,
'using_hash_resource'
]
...
...
@@ -623,12 +623,14 @@ def setup
super
@request
.
host
=
"www.example.com"
Mime
::
Type
.
register_alias
(
'text/html'
,
:iphone
)
Mime
::
Type
.
register_alias
(
'text/html'
,
:touch
)
Mime
::
Type
.
register
(
'text/x-mobile'
,
:mobile
)
end
def
teardown
super
Mime
::
Type
.
unregister
(
:iphone
)
Mime
::
Type
.
unregister
(
:touch
)
Mime
::
Type
.
unregister
(
:mobile
)
end
...
...
actionpack/test/dispatch/mime_type_test.rb
浏览文件 @
cb46e7a7
...
...
@@ -118,6 +118,20 @@ class MimeTypeTest < ActiveSupport::TestCase
end
end
test
"register callbacks"
do
begin
registered_mimes
=
[]
Mime
::
Type
.
register_callback
do
|
mime
|
registered_mimes
<<
mime
end
Mime
::
Type
.
register
(
"text/foo"
,
:foo
)
assert_equal
registered_mimes
,
[
Mime
::
FOO
]
ensure
Mime
::
Type
.
unregister
(
:FOO
)
end
end
test
"custom type with extension aliases"
do
begin
Mime
::
Type
.
register
"text/foobar"
,
:foobar
,
[],
[
:foo
,
"bar"
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录