Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
7f4d8e3f
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 搜索 >>
提交
7f4d8e3f
编写于
1月 15, 2010
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Yield the payload notifications for further modification (like adding the result).
上级
b0994be5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
8 addition
and
14 deletion
+8
-14
activeresource/lib/active_resource/connection.rb
activeresource/lib/active_resource/connection.rb
+3
-3
activesupport/lib/active_support/notifications.rb
activesupport/lib/active_support/notifications.rb
+1
-1
activesupport/lib/active_support/notifications/instrumenter.rb
...esupport/lib/active_support/notifications/instrumenter.rb
+2
-8
activesupport/test/notifications_test.rb
activesupport/test/notifications_test.rb
+2
-2
未找到文件。
activeresource/lib/active_resource/connection.rb
浏览文件 @
7f4d8e3f
...
...
@@ -106,9 +106,9 @@ def head(path, headers = {})
private
# Makes a request to the remote service.
def
request
(
method
,
path
,
*
arguments
)
result
=
ActiveSupport
::
Notifications
.
instrument
!
(
"active_resource.request"
,
:method
=>
method
,
:path
=>
path
,
:site
=>
site
)
do
http
.
send
(
method
,
path
,
*
arguments
)
result
=
ActiveSupport
::
Notifications
.
instrument
(
"active_resource.request"
,
:method
=>
method
,
:path
=>
path
,
:site
=>
site
)
do
|
payload
|
payload
[
:result
]
=
http
.
send
(
method
,
path
,
*
arguments
)
end
handle_response
(
result
)
rescue
Timeout
::
Error
=>
e
...
...
activesupport/lib/active_support/notifications.rb
浏览文件 @
7f4d8e3f
...
...
@@ -45,7 +45,7 @@ module Notifications
class
<<
self
attr_writer
:notifier
delegate
:publish
,
:subscribe
,
:to
=>
:notifier
delegate
:instrument
,
:
instrument!
,
:
to
=>
:instrumenter
delegate
:instrument
,
:to
=>
:instrumenter
def
notifier
@notifier
||=
Notifier
.
new
...
...
activesupport/lib/active_support/notifications/instrumenter.rb
浏览文件 @
7f4d8e3f
...
...
@@ -13,19 +13,13 @@ def initialize(notifier)
# Instrument the given block by measuring the time taken to execute it
# and publish it.
def
instrument
(
name
,
payload
=
{}
,
add_result
=
false
)
def
instrument
(
name
,
payload
=
{})
time
=
Time
.
now
result
=
yield
if
block_given?
payload
.
merge!
(
:result
=>
result
)
if
add_result
result
=
yield
(
payload
)
if
block_given?
@notifier
.
publish
(
name
,
time
,
Time
.
now
,
@id
,
payload
)
result
end
# The same as instrument, but adds the result as payload.
def
instrument!
(
name
,
payload
=
{},
&
block
)
instrument
(
name
,
payload
,
true
,
&
block
)
end
private
def
unique_id
SecureRandom
.
hex
(
10
)
...
...
activesupport/test/notifications_test.rb
浏览文件 @
7f4d8e3f
...
...
@@ -90,8 +90,8 @@ def test_instrument_returns_block_result
drain
end
def
test_instrument_
with_band_adds_result_to_payload
assert_equal
2
,
instrument
!
(
:awesome
)
{
1
+
1
}
def
test_instrument_
yields_the_paylod_for_further_modification
assert_equal
2
,
instrument
(
:awesome
)
{
|
p
|
p
[
:result
]
=
1
+
1
}
drain
assert_equal
1
,
@events
.
size
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录