Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
bb4de3a5
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 搜索 >>
提交
bb4de3a5
编写于
2月 05, 2012
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4886 from bogdan/callbacks_cleanup
AS::Callbacks: remove unused code
上级
a9bebaed
24b75fc4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
13 addition
and
17 deletion
+13
-17
activesupport/lib/active_support/callbacks.rb
activesupport/lib/active_support/callbacks.rb
+13
-17
未找到文件。
activesupport/lib/active_support/callbacks.rb
浏览文件 @
bb4de3a5
...
@@ -66,8 +66,6 @@ module Callbacks
...
@@ -66,8 +66,6 @@ module Callbacks
#
#
# Calls the before and around callbacks in the order they were set, yields
# Calls the before and around callbacks in the order they were set, yields
# the block (if given one), and then runs the after callbacks in reverse order.
# the block (if given one), and then runs the after callbacks in reverse order.
# Optionally accepts a key, which will be used to compile an optimized callback
# method for each key. See +ClassMethods.define_callbacks+ for more information.
#
#
# If the callback chain was halted, returns +false+. Otherwise returns the result
# If the callback chain was halted, returns +false+. Otherwise returns the result
# of the block, or +true+ if no block is given.
# of the block, or +true+ if no block is given.
...
@@ -77,7 +75,8 @@ module Callbacks
...
@@ -77,7 +75,8 @@ module Callbacks
# end
# end
#
#
def
run_callbacks
(
kind
,
key
=
nil
,
&
block
)
def
run_callbacks
(
kind
,
key
=
nil
,
&
block
)
self
.
class
.
__run_callbacks
(
key
,
kind
,
self
,
&
block
)
#TODO: deprecate key argument
self
.
class
.
__run_callbacks
(
kind
,
self
,
&
block
)
end
end
private
private
...
@@ -100,8 +99,7 @@ def initialize(chain, filter, kind, options, klass)
...
@@ -100,8 +99,7 @@ def initialize(chain, filter, kind, options, klass)
@raw_filter
,
@options
=
filter
,
options
@raw_filter
,
@options
=
filter
,
options
@filter
=
_compile_filter
(
filter
)
@filter
=
_compile_filter
(
filter
)
@compiled_options
=
_compile_options
(
options
)
recompile_options!
@callback_id
=
next_id
end
end
def
deprecate_per_key_option
(
options
)
def
deprecate_per_key_option
(
options
)
...
@@ -146,13 +144,11 @@ def recompile!(_options)
...
@@ -146,13 +144,11 @@ def recompile!(_options)
deprecate_per_key_option
(
_options
)
deprecate_per_key_option
(
_options
)
_update_filter
(
self
.
options
,
_options
)
_update_filter
(
self
.
options
,
_options
)
@callback_id
=
next_id
recompile_options!
@filter
=
_compile_filter
(
@raw_filter
)
@compiled_options
=
_compile_options
(
@options
)
end
end
# Wraps code with filter
# Wraps code with filter
def
apply
(
code
,
key
=
nil
,
object
=
nil
)
def
apply
(
code
)
case
@kind
case
@kind
when
:before
when
:before
<<-
RUBY_EVAL
<<-
RUBY_EVAL
...
@@ -222,7 +218,7 @@ def #{name}(halted)
...
@@ -222,7 +218,7 @@ def #{name}(halted)
# Options support the same options as filters themselves (and support
# Options support the same options as filters themselves (and support
# symbols, string, procs, and objects), so compile a conditional
# symbols, string, procs, and objects), so compile a conditional
# expression based on the options
# expression based on the options
def
_compile_options
(
options
)
def
recompile_options!
conditions
=
[
"true"
]
conditions
=
[
"true"
]
unless
options
[
:if
].
empty?
unless
options
[
:if
].
empty?
...
@@ -233,7 +229,7 @@ def _compile_options(options)
...
@@ -233,7 +229,7 @@ def _compile_options(options)
conditions
<<
Array
(
_compile_filter
(
options
[
:unless
])).
map
{
|
f
|
"!
#{
f
}
"
}
conditions
<<
Array
(
_compile_filter
(
options
[
:unless
])).
map
{
|
f
|
"!
#{
f
}
"
}
end
end
conditions
.
flatten
.
join
(
" && "
)
@compiled_options
=
conditions
.
flatten
.
join
(
" && "
)
end
end
# Filters support:
# Filters support:
...
@@ -316,14 +312,14 @@ def initialize(name, config)
...
@@ -316,14 +312,14 @@ def initialize(name, config)
}.
merge
(
config
)
}.
merge
(
config
)
end
end
def
compile
(
key
=
nil
,
object
=
nil
)
def
compile
method
=
[]
method
=
[]
method
<<
"value = nil"
method
<<
"value = nil"
method
<<
"halted = false"
method
<<
"halted = false"
callbacks
=
yielding
callbacks
=
yielding
reverse_each
do
|
callback
|
reverse_each
do
|
callback
|
callbacks
=
callback
.
apply
(
callbacks
,
key
,
object
)
callbacks
=
callback
.
apply
(
callbacks
)
end
end
method
<<
callbacks
method
<<
callbacks
...
@@ -354,14 +350,14 @@ def yielding
...
@@ -354,14 +350,14 @@ def yielding
module
ClassMethods
module
ClassMethods
# This method runs callback chain for the given k
ey
.
# This method runs callback chain for the given k
ind
.
# If this called first time it creates a new callback method for the k
ey
.
# If this called first time it creates a new callback method for the k
ind
.
# This generated method plays caching role.
# This generated method plays caching role.
#
#
def
__run_callbacks
(
k
ey
,
k
ind
,
object
,
&
blk
)
#:nodoc:
def
__run_callbacks
(
kind
,
object
,
&
blk
)
#:nodoc:
name
=
__callback_runner_name
(
kind
)
name
=
__callback_runner_name
(
kind
)
unless
object
.
respond_to?
(
name
)
unless
object
.
respond_to?
(
name
)
str
=
object
.
send
(
"_
#{
kind
}
_callbacks"
).
compile
(
key
,
object
)
str
=
object
.
send
(
"_
#{
kind
}
_callbacks"
).
compile
class_eval
<<-
RUBY_EVAL
,
__FILE__
,
__LINE__
+
1
class_eval
<<-
RUBY_EVAL
,
__FILE__
,
__LINE__
+
1
def
#{
name
}
()
#{
str
}
end
def
#{
name
}
()
#{
str
}
end
protected :
#{
name
}
protected :
#{
name
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录