Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
5d6b5433
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,体验更适合开发者的 AI 搜索 >>
提交
5d6b5433
编写于
4月 24, 2015
作者:
Z
Zachary Scott
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19894 from thenickcox/deprecated_proxy_docs
[ci skip] Rework docs, add examples on deprecation proxies
上级
dc698444
ea30e329
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
38 addition
and
22 deletion
+38
-22
activesupport/lib/active_support/deprecation/proxy_wrappers.rb
...esupport/lib/active_support/deprecation/proxy_wrappers.rb
+38
-22
未找到文件。
activesupport/lib/active_support/deprecation/proxy_wrappers.rb
浏览文件 @
5d6b5433
...
...
@@ -25,15 +25,17 @@ def method_missing(called, *args, &block)
end
end
# This DeprecatedObjectProxy transforms object to deprecated object.
# DeprecatedObjectProxy transforms an object into a deprecated object. It takes an object,
# a deprecation message, and optionally a deprecator. The deprecator defaults to
# <tt>ActiveSupport::Deprecator</tt> if none is specified.
#
#
@old_object = DeprecatedObjectProxy.new(Object.new, "Don't use this object anymore!
")
#
@old_object = DeprecatedObjectProxy.new(Object.new, "Don't use this object anymore!", deprecator_instance)
#
deprecated_object = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(Object.new, "This object is now deprecated
")
#
# => <Object:0x007fb9b34c34b0>
#
#
When someone executes any method except +inspect+ on proxy object this will
#
trigger +warn+ method on +deprecator_instance+
.
#
#
Default deprecator is <tt>ActiveSupport::Deprecation</tt>
#
deprecated_object.to_s
#
DEPRECATION WARNING: This object is now deprecated
.
#
(Backtrace)
#
# => "<Object:0x007fb9b34c34b0>"
class
DeprecatedObjectProxy
<
DeprecationProxy
def
initialize
(
object
,
message
,
deprecator
=
ActiveSupport
::
Deprecation
.
instance
)
@object
=
object
...
...
@@ -51,13 +53,15 @@ def warn(callstack, called, args)
end
end
# This DeprecatedInstanceVariableProxy transforms instance variable to
# deprecated instance variable.
# DeprecatedInstanceVariableProxy transforms an instance variable into a deprecated
# instance variable. It takes an instance of a class, a method on that class, and an
# instance variable. It optionally takes a deprecator as the last argument. The deprecator
# defaults to <tt>ActiveSupport::Deprecator</tt> if none is specified.
#
# class Example
# def initialize
(deprecator)
# def initialize
# @request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request, :@request, deprecator)
# @_request = :
a
_request
# @_request = :
special
_request
# end
#
# def request
...
...
@@ -69,12 +73,17 @@ def warn(callstack, called, args)
# end
# end
#
# When someone execute any method on @request variable this will trigger
# +warn+ method on +deprecator_instance+ and will fetch <tt>@_request</tt>
# variable via +request+ method and execute the same method on non-proxy
# instance variable.
# example = Example.new
# # => #<Example:0x007fb9b31090b8 @_request=:special_request, @request=:special_request>
#
# example.old_request.to_s
# # => DEPRECATION WARNING: @request is deprecated! Call request.to_s instead of
# @request.to_s
# (Bactrace information…)
# "special_request"
#
# Default deprecator is <tt>ActiveSupport::Deprecation</tt>.
# example.request.to_s
# # => "special_request"
class
DeprecatedInstanceVariableProxy
<
DeprecationProxy
def
initialize
(
instance
,
method
,
var
=
"@
#{
method
}
"
,
deprecator
=
ActiveSupport
::
Deprecation
.
instance
)
@instance
=
instance
...
...
@@ -93,15 +102,22 @@ def warn(callstack, called, args)
end
end
# This DeprecatedConstantProxy transforms constant to deprecated constant.
# DeprecatedConstantProxy transforms a constant into a deprecated constant. It takes the names of an old
# (deprecated) constant and a new contstant (both in string form), and optionally a deprecator. The
# deprecator defaults to <tt>ActiveSupport::Deprecator</tt> if none is specified. The deprecated constant
# now returns the return value of the new constant.
#
# PLANETS = %w(mercury venus earth mars jupiter saturn uranus neptune pluto)
#
# OLD_CONST = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('OLD_CONST', 'NEW_CONST')
# OLD_CONST = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('OLD_CONST', 'NEW_CONST', deprecator_instance)
# (In a later update, the orignal implementation of `PLANETS` has been removed.)
#
#
When someone use old constant this will trigger +warn+ method on
#
+deprecator_instance+.
#
PLANETS_POST_2006 = %w(mercury venus earth mars jupiter saturn uranus neptune)
#
PLANETS = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('PLANETS', 'PLANETS_POST_2006')
#
# Default deprecator is <tt>ActiveSupport::Deprecation</tt>.
# PLANETS.map { |planet| planet.capitalize }
# # => DEPRECATION WARNING: PLANETS is deprecated! Use PLANETS_POST_2006 instead.
# (Bactrace information…)
# ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
class
DeprecatedConstantProxy
<
DeprecationProxy
def
initialize
(
old_const
,
new_const
,
deprecator
=
ActiveSupport
::
Deprecation
.
instance
)
@old_const
=
old_const
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录