Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
e15583c3
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,发现更多精彩内容 >>
提交
e15583c3
编写于
8月 16, 2017
作者:
A
Alberto Almagro
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Pass missing name attribute to execute_hook
Fixes commit
10bf93ef
created to solve issue #30025
上级
00a47d58
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
12 addition
and
7 deletion
+12
-7
activesupport/lib/active_support/lazy_load_hooks.rb
activesupport/lib/active_support/lazy_load_hooks.rb
+3
-3
activesupport/test/lazy_load_hooks_test.rb
activesupport/test/lazy_load_hooks_test.rb
+9
-4
未找到文件。
activesupport/lib/active_support/lazy_load_hooks.rb
浏览文件 @
e15583c3
...
@@ -40,7 +40,7 @@ def self.extended(base) # :nodoc:
...
@@ -40,7 +40,7 @@ def self.extended(base) # :nodoc:
# * <tt>:run_once</tt> - Given +block+ will run only once.
# * <tt>:run_once</tt> - Given +block+ will run only once.
def
on_load
(
name
,
options
=
{},
&
block
)
def
on_load
(
name
,
options
=
{},
&
block
)
@loaded
[
name
].
each
do
|
base
|
@loaded
[
name
].
each
do
|
base
|
execute_hook
(
base
,
options
,
block
)
execute_hook
(
name
,
base
,
options
,
block
)
end
end
@load_hooks
[
name
]
<<
[
block
,
options
]
@load_hooks
[
name
]
<<
[
block
,
options
]
...
@@ -49,7 +49,7 @@ def on_load(name, options = {}, &block)
...
@@ -49,7 +49,7 @@ def on_load(name, options = {}, &block)
def
run_load_hooks
(
name
,
base
=
Object
)
def
run_load_hooks
(
name
,
base
=
Object
)
@loaded
[
name
]
<<
base
@loaded
[
name
]
<<
base
@load_hooks
[
name
].
each
do
|
hook
,
options
|
@load_hooks
[
name
].
each
do
|
hook
,
options
|
execute_hook
(
base
,
options
,
hook
)
execute_hook
(
name
,
base
,
options
,
hook
)
end
end
end
end
...
@@ -63,7 +63,7 @@ def with_execution_control(name, block, once)
...
@@ -63,7 +63,7 @@ def with_execution_control(name, block, once)
end
end
end
end
def
execute_hook
(
base
,
options
,
block
)
def
execute_hook
(
name
,
base
,
options
,
block
)
with_execution_control
(
name
,
block
,
options
[
:run_once
])
do
with_execution_control
(
name
,
block
,
options
[
:run_once
])
do
if
options
[
:yield
]
if
options
[
:yield
]
block
.
call
(
base
)
block
.
call
(
base
)
...
...
activesupport/test/lazy_load_hooks_test.rb
浏览文件 @
e15583c3
...
@@ -22,14 +22,19 @@ def test_basic_hook_with_two_registrations
...
@@ -22,14 +22,19 @@ def test_basic_hook_with_two_registrations
def
test_basic_hook_with_two_registrations_only_once
def
test_basic_hook_with_two_registrations_only_once
i
=
0
i
=
0
ActiveSupport
.
on_load
(
:basic_hook_with_two_once
,
run_once:
true
)
do
block
=
proc
{
i
+=
incr
}
ActiveSupport
.
on_load
(
:basic_hook_with_two_once
,
run_once:
true
,
&
block
)
ActiveSupport
.
on_load
(
:basic_hook_with_two_once
)
do
i
+=
incr
i
+=
incr
end
end
assert_equal
0
,
i
ActiveSupport
.
run_load_hooks
(
:basic_hook_with_two_once
,
FakeContext
.
new
(
2
))
ActiveSupport
.
on_load
(
:different_hook
,
run_once:
true
,
&
block
)
ActiveSupport
.
run_load_hooks
(
:different_hook
,
FakeContext
.
new
(
2
))
assert_equal
2
,
i
assert_equal
2
,
i
ActiveSupport
.
run_load_hooks
(
:basic_hook_with_two_once
,
FakeContext
.
new
(
2
))
assert_equal
6
,
i
ActiveSupport
.
run_load_hooks
(
:basic_hook_with_two_once
,
FakeContext
.
new
(
5
))
ActiveSupport
.
run_load_hooks
(
:basic_hook_with_two_once
,
FakeContext
.
new
(
5
))
assert_equal
2
,
i
assert_equal
11
,
i
end
end
def
test_hook_registered_after_run
def
test_hook_registered_after_run
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录