Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
ccab1b2d
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,发现更多精彩内容 >>
提交
ccab1b2d
编写于
3月 22, 2017
作者:
R
Rafael França
提交者:
GitHub
3月 22, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #28528 from domcleal/parseerror-const-deprecation
Change AD::ParamsParser::ParseError deprecation so it can be rescued
上级
36334bf9
d5ea4bde
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
88 addition
and
1 deletion
+88
-1
actionpack/lib/action_dispatch/http/parameters.rb
actionpack/lib/action_dispatch/http/parameters.rb
+2
-1
activesupport/CHANGELOG.md
activesupport/CHANGELOG.md
+12
-0
activesupport/lib/active_support/deprecation.rb
activesupport/lib/active_support/deprecation.rb
+1
-0
activesupport/lib/active_support/deprecation/constant_accessor.rb
...pport/lib/active_support/deprecation/constant_accessor.rb
+50
-0
activesupport/test/deprecation_test.rb
activesupport/test/deprecation_test.rb
+23
-0
未找到文件。
actionpack/lib/action_dispatch/http/parameters.rb
浏览文件 @
ccab1b2d
...
...
@@ -115,6 +115,7 @@ def params_parsers
end
module
ParamsParser
ParseError
=
ActiveSupport
::
Deprecation
::
DeprecatedConstantProxy
.
new
(
"ActionDispatch::ParamsParser::ParseError"
,
"ActionDispatch::Http::Parameters::ParseError"
)
include
ActiveSupport
::
Deprecation
::
DeprecatedConstantAccessor
deprecate_constant
"ParseError"
,
"ActionDispatch::Http::Parameters::ParseError"
end
end
activesupport/CHANGELOG.md
浏览文件 @
ccab1b2d
*
Add ActiveSupport::Deprecation::DeprecatedConstantAccessor
Provides transparent deprecation of constants, compatible with exceptions.
Example usage:
module Example
include ActiveSupport::Deprecation::DeprecatedConstantAccessor
deprecate_constant 'OldException', 'Elsewhere::NewException'
end
*Dominic Cleal*
Please check
[
5-1-stable
](
https://github.com/rails/rails/blob/5-1-stable/activesupport/CHANGELOG.md
)
for previous changes.
activesupport/lib/active_support/deprecation.rb
浏览文件 @
ccab1b2d
...
...
@@ -15,6 +15,7 @@ class Deprecation
require
"active_support/deprecation/instance_delegator"
require
"active_support/deprecation/behaviors"
require
"active_support/deprecation/reporting"
require
"active_support/deprecation/constant_accessor"
require
"active_support/deprecation/method_wrappers"
require
"active_support/deprecation/proxy_wrappers"
require
"active_support/core_ext/module/deprecation"
...
...
activesupport/lib/active_support/deprecation/constant_accessor.rb
0 → 100644
浏览文件 @
ccab1b2d
require
"active_support/inflector/methods"
module
ActiveSupport
class
Deprecation
# DeprecatedConstantAccessor transforms a constant into a deprecated one by
# hooking +const_missing+.
#
# It takes the names of an old (deprecated) constant and of a new constant
# (both in string form) and optionally a deprecator. The deprecator defaults
# to +ActiveSupport::Deprecator+ if none is specified.
#
# The deprecated constant now returns the same object as the new one rather
# than a proxy object, so it can be used transparently in +rescue+ blocks
# etc.
#
# PLANETS = %w(mercury venus earth mars jupiter saturn uranus neptune pluto)
#
# (In a later update, the original implementation of `PLANETS` has been removed.)
#
# PLANETS_POST_2006 = %w(mercury venus earth mars jupiter saturn uranus neptune)
# include ActiveSupport::Deprecation::DeprecatedConstantAccessor
# deprecate_constant 'PLANETS', 'PLANETS_POST_2006'
#
# PLANETS.map { |planet| planet.capitalize }
# # => DEPRECATION WARNING: PLANETS is deprecated! Use PLANETS_POST_2006 instead.
# (Backtrace information…)
# ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
module
DeprecatedConstantAccessor
def
self
.
included
(
base
)
extension
=
Module
.
new
do
def
const_missing
(
missing_const_name
)
if
class_variable_defined?
(
:@@_deprecated_constants
)
if
(
replacement
=
class_variable_get
(
:@@_deprecated_constants
)[
missing_const_name
.
to_s
])
replacement
[
:deprecator
].
warn
(
replacement
[
:message
]
||
"
#{
name
}
::
#{
missing_const_name
}
is deprecated! Use
#{
replacement
[
:new
]
}
instead."
,
caller_locations
)
return
ActiveSupport
::
Inflector
.
constantize
(
replacement
[
:new
].
to_s
)
end
end
super
end
def
deprecate_constant
(
const_name
,
new_constant
,
message:
nil
,
deprecator:
ActiveSupport
::
Deprecation
.
instance
)
class_variable_set
(
:@@_deprecated_constants
,
{})
unless
class_variable_defined?
(
:@@_deprecated_constants
)
class_variable_get
(
:@@_deprecated_constants
)[
const_name
.
to_s
]
=
{
new:
new_constant
,
message:
message
,
deprecator:
deprecator
}
end
end
base
.
singleton_class
.
prepend
extension
end
end
end
end
activesupport/test/deprecation_test.rb
浏览文件 @
ccab1b2d
...
...
@@ -35,6 +35,18 @@ module B
A
=
ActiveSupport
::
Deprecation
::
DeprecatedConstantProxy
.
new
(
"Deprecatee::A"
,
"Deprecatee::B::C"
)
end
class
DeprecateeWithAccessor
include
ActiveSupport
::
Deprecation
::
DeprecatedConstantAccessor
module
B
C
=
1
end
deprecate_constant
"A"
,
"DeprecateeWithAccessor::B::C"
class
NewException
<
StandardError
;
end
deprecate_constant
"OldException"
,
"DeprecateeWithAccessor::NewException"
end
class
DeprecationTest
<
ActiveSupport
::
TestCase
include
ActiveSupport
::
Testing
::
Stream
...
...
@@ -162,6 +174,17 @@ def test_deprecated_constant_proxy
assert_not_deprecated
{
assert_equal
Deprecatee
::
B
::
C
.
class
,
Deprecatee
::
A
.
class
}
end
def
test_deprecated_constant_accessor
assert_not_deprecated
{
DeprecateeWithAccessor
::
B
::
C
}
assert_deprecated
(
"DeprecateeWithAccessor::A"
)
{
assert_equal
DeprecateeWithAccessor
::
B
::
C
,
DeprecateeWithAccessor
::
A
}
end
def
test_deprecated_constant_accessor_exception
raise
DeprecateeWithAccessor
::
NewException
.
new
(
"Test"
)
rescue
DeprecateeWithAccessor
::
OldException
=>
e
assert_kind_of
DeprecateeWithAccessor
::
NewException
,
e
end
def
test_assert_deprecated_raises_when_method_not_deprecated
assert_raises
(
Minitest
::
Assertion
)
{
assert_deprecated
{
@dtc
.
not
}
}
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录