Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a2b7fcb0
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,发现更多精彩内容 >>
提交
a2b7fcb0
编写于
6月 19, 2010
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change callbacks to automatically include DescendantsTracker and rename descendents to descendants.
上级
8db8c6f4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
17 addition
and
10 deletion
+17
-10
activesupport/lib/active_support/callbacks.rb
activesupport/lib/active_support/callbacks.rb
+7
-3
activesupport/lib/active_support/core_ext/class/subclasses.rb
...vesupport/lib/active_support/core_ext/class/subclasses.rb
+5
-5
activesupport/test/descendants_tracker_test.rb
activesupport/test/descendants_tracker_test.rb
+5
-2
未找到文件。
activesupport/lib/active_support/callbacks.rb
浏览文件 @
a2b7fcb0
require
'active_support/descendants_tracker'
require
'active_support/core_ext/array/wrap'
require
'active_support/core_ext/class/inheritable_attributes'
require
'active_support/core_ext/class/subclasses'
require
'active_support/core_ext/kernel/reporting'
require
'active_support/core_ext/kernel/singleton_class'
...
...
@@ -85,6 +85,10 @@ module ActiveSupport
module
Callbacks
extend
Concern
included
do
extend
ActiveSupport
::
DescendantsTracker
end
def
run_callbacks
(
kind
,
*
args
,
&
block
)
send
(
"_run_
#{
kind
}
_callbacks"
,
*
args
,
&
block
)
end
...
...
@@ -428,7 +432,7 @@ def __update_callbacks(name, filters = [], block = nil) #:nodoc:
options
=
filters
.
last
.
is_a?
(
Hash
)
?
filters
.
pop
:
{}
filters
.
unshift
(
block
)
if
block
([
self
]
+
self
.
descend
e
nts
).
each
do
|
target
|
([
self
]
+
self
.
descend
a
nts
).
each
do
|
target
|
chain
=
target
.
send
(
"_
#{
name
}
_callbacks"
)
yield
chain
,
type
,
filters
,
options
target
.
__define_runner
(
name
)
...
...
@@ -502,7 +506,7 @@ def skip_callback(name, *filter_list, &block)
def
reset_callbacks
(
symbol
)
callbacks
=
send
(
"_
#{
symbol
}
_callbacks"
)
self
.
descend
e
nts
.
each
do
|
target
|
self
.
descend
a
nts
.
each
do
|
target
|
chain
=
target
.
send
(
"_
#{
symbol
}
_callbacks"
)
callbacks
.
each
{
|
c
|
chain
.
delete
(
c
)
}
target
.
__define_runner
(
symbol
)
...
...
activesupport/lib/active_support/core_ext/class/subclasses.rb
浏览文件 @
a2b7fcb0
...
...
@@ -11,9 +11,9 @@ def subclasses
# Rubinius
if
defined?
(
Class
.
__subclasses__
)
def
descend
e
nts
def
descend
a
nts
subclasses
=
[]
__subclasses__
.
each
{
|
k
|
subclasses
<<
k
;
subclasses
.
concat
k
.
descend
e
nts
}
__subclasses__
.
each
{
|
k
|
subclasses
<<
k
;
subclasses
.
concat
k
.
descend
a
nts
}
subclasses
end
else
...
...
@@ -21,7 +21,7 @@ def descendents
begin
ObjectSpace
.
each_object
(
Class
.
new
)
{}
def
descend
e
nts
def
descend
a
nts
subclasses
=
[]
ObjectSpace
.
each_object
(
class
<<
self
;
self
;
end
)
do
|
k
|
subclasses
<<
k
unless
k
==
self
...
...
@@ -30,7 +30,7 @@ def descendents
end
# JRuby
rescue
StandardError
def
descend
e
nts
def
descend
a
nts
subclasses
=
[]
ObjectSpace
.
each_object
(
Class
)
do
|
k
|
subclasses
<<
k
if
k
<
self
...
...
@@ -48,7 +48,7 @@ def descendents
def
self
.
subclasses_of
(
*
superclasses
)
#:nodoc:
subclasses
=
[]
superclasses
.
each
do
|
klass
|
subclasses
.
concat
klass
.
descend
e
nts
.
select
{
|
k
|
k
.
anonymous?
||
k
.
reachable?
}
subclasses
.
concat
klass
.
descend
a
nts
.
select
{
|
k
|
k
.
anonymous?
||
k
.
reachable?
}
end
subclasses
end
...
...
activesupport/test/descendants_tracker_test.rb
浏览文件 @
a2b7fcb0
require
'abstract_unit'
require
'test/unit'
require
'active_support'
require
'active_support/core_ext/hash/slice'
class
DescendantsTrackerTest
<
Test
::
Unit
::
TestCase
class
Parent
...
...
@@ -19,6 +20,8 @@ class Grandchild1 < Child1
class
Grandchild2
<
Child1
end
ALL
=
[
Parent
,
Child1
,
Child2
,
Grandchild1
,
Grandchild2
]
def
test_descendants
assert_equal
[
Child1
,
Grandchild1
,
Grandchild2
,
Child2
],
Parent
.
descendants
assert_equal
[
Grandchild1
,
Grandchild2
],
Child1
.
descendants
...
...
@@ -32,9 +35,9 @@ def test_direct_descendants
end
def
test_clear_with_autoloaded_parent_children_and_granchildren
mark_as_autoloaded
Parent
,
Child1
,
Child2
,
Grandchild1
,
Grandchild2
do
mark_as_autoloaded
*
ALL
do
ActiveSupport
::
DescendantsTracker
.
clear
assert
_equal
Hash
.
new
,
ActiveSupport
::
DescendantsTracker
.
descendants
assert
ActiveSupport
::
DescendantsTracker
.
descendants
.
slice
(
*
ALL
).
empty?
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录