Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b41ef0a4
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 搜索 >>
提交
b41ef0a4
编写于
2月 04, 2012
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4866 from bogdan/terminate_after_callbacks
AS::Callbacks#define_callbacks: add :terminate_after_callbacks option
上级
d709b124
76619556
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
12 addition
and
7 deletion
+12
-7
actionpack/lib/abstract_controller/callbacks.rb
actionpack/lib/abstract_controller/callbacks.rb
+1
-3
activemodel/lib/active_model/callbacks.rb
activemodel/lib/active_model/callbacks.rb
+2
-1
activemodel/lib/active_model/validations/callbacks.rb
activemodel/lib/active_model/validations/callbacks.rb
+1
-2
activesupport/CHANGELOG.md
activesupport/CHANGELOG.md
+2
-0
activesupport/lib/active_support/callbacks.rb
activesupport/lib/active_support/callbacks.rb
+6
-1
未找到文件。
actionpack/lib/abstract_controller/callbacks.rb
浏览文件 @
b41ef0a4
...
@@ -8,7 +8,7 @@ module Callbacks
...
@@ -8,7 +8,7 @@ module Callbacks
include
ActiveSupport
::
Callbacks
include
ActiveSupport
::
Callbacks
included
do
included
do
define_callbacks
:process_action
,
:terminator
=>
"response_body"
define_callbacks
:process_action
,
:terminator
=>
"response_body"
,
:skip_after_callbacks_if_terminated
=>
true
end
end
# Override AbstractController::Base's process_action to run the
# Override AbstractController::Base's process_action to run the
...
@@ -165,7 +165,6 @@ def _insert_callbacks(callbacks, block)
...
@@ -165,7 +165,6 @@ def _insert_callbacks(callbacks, block)
# for details on the allowed parameters.
# for details on the allowed parameters.
def
#{
filter
}
_filter(*names, &blk) # def before_filter(*names, &blk)
def
#{
filter
}
_filter(*names, &blk) # def before_filter(*names, &blk)
_insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options|
_insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options|
options[:if] = (Array(options[:if]) << "!halted") if
#{
filter
==
:after
}
# options[:if] = (Array(options[:if]) << "!halted") if false
set_callback(:process_action, :
#{
filter
}
, name, options) # set_callback(:process_action, :before, name, options)
set_callback(:process_action, :
#{
filter
}
, name, options) # set_callback(:process_action, :before, name, options)
end # end
end # end
end # end
end # end
...
@@ -174,7 +173,6 @@ def #{filter}_filter(*names, &blk)
...
@@ -174,7 +173,6 @@ def #{filter}_filter(*names, &blk)
# for details on the allowed parameters.
# for details on the allowed parameters.
def prepend_
#{
filter
}
_filter(*names, &blk) # def prepend_before_filter(*names, &blk)
def prepend_
#{
filter
}
_filter(*names, &blk) # def prepend_before_filter(*names, &blk)
_insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options|
_insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options|
options[:if] = (Array(options[:if]) << "!halted") if
#{
filter
==
:after
}
# options[:if] = (Array(options[:if]) << "!halted") if false
set_callback(:process_action, :
#{
filter
}
, name, options.merge(:prepend => true)) # set_callback(:process_action, :before, name, options.merge(:prepend => true))
set_callback(:process_action, :
#{
filter
}
, name, options.merge(:prepend => true)) # set_callback(:process_action, :before, name, options.merge(:prepend => true))
end # end
end # end
end # end
end # end
...
...
activemodel/lib/active_model/callbacks.rb
浏览文件 @
b41ef0a4
...
@@ -88,6 +88,7 @@ def define_model_callbacks(*callbacks)
...
@@ -88,6 +88,7 @@ def define_model_callbacks(*callbacks)
options
=
callbacks
.
extract_options!
options
=
callbacks
.
extract_options!
options
=
{
options
=
{
:terminator
=>
"result == false"
,
:terminator
=>
"result == false"
,
:skip_after_callbacks_if_terminated
=>
true
,
:scope
=>
[
:kind
,
:name
],
:scope
=>
[
:kind
,
:name
],
:only
=>
[
:before
,
:around
,
:after
]
:only
=>
[
:before
,
:around
,
:after
]
}.
merge
(
options
)
}.
merge
(
options
)
...
@@ -124,7 +125,7 @@ def _define_after_model_callback(klass, callback) #:nodoc:
...
@@ -124,7 +125,7 @@ def _define_after_model_callback(klass, callback) #:nodoc:
def self.after_
#{
callback
}
(*args, &block)
def self.after_
#{
callback
}
(*args, &block)
options = args.extract_options!
options = args.extract_options!
options[:prepend] = true
options[:prepend] = true
options[:if] = Array(options[:if]) << "
!halted &&
value != false"
options[:if] = Array(options[:if]) << "value != false"
set_callback(:
#{
callback
}
, :after, *(args << options), &block)
set_callback(:
#{
callback
}
, :after, *(args << options), &block)
end
end
CALLBACK
CALLBACK
...
...
activemodel/lib/active_model/validations/callbacks.rb
浏览文件 @
b41ef0a4
...
@@ -23,7 +23,7 @@ module Callbacks
...
@@ -23,7 +23,7 @@ module Callbacks
included
do
included
do
include
ActiveSupport
::
Callbacks
include
ActiveSupport
::
Callbacks
define_callbacks
:validation
,
:terminator
=>
"result == false"
,
:scope
=>
[
:kind
,
:name
]
define_callbacks
:validation
,
:terminator
=>
"result == false"
,
:s
kip_after_callbacks_if_terminated
=>
true
,
:s
cope
=>
[
:kind
,
:name
]
end
end
module
ClassMethods
module
ClassMethods
...
@@ -40,7 +40,6 @@ def after_validation(*args, &block)
...
@@ -40,7 +40,6 @@ def after_validation(*args, &block)
options
=
args
.
extract_options!
options
=
args
.
extract_options!
options
[
:prepend
]
=
true
options
[
:prepend
]
=
true
options
[
:if
]
=
Array
(
options
[
:if
])
options
[
:if
]
=
Array
(
options
[
:if
])
options
[
:if
]
<<
"!halted"
options
[
:if
].
unshift
(
"self.validation_context == :
#{
options
[
:on
]
}
"
)
if
options
[
:on
]
options
[
:if
].
unshift
(
"self.validation_context == :
#{
options
[
:on
]
}
"
)
if
options
[
:on
]
set_callback
(
:validation
,
:after
,
*
(
args
<<
options
),
&
block
)
set_callback
(
:validation
,
:after
,
*
(
args
<<
options
),
&
block
)
end
end
...
...
activesupport/CHANGELOG.md
浏览文件 @
b41ef0a4
## Rails 4.0.0 (unreleased) ##
## Rails 4.0.0 (unreleased) ##
*
`AS::Callbacks#define_callbacks`
: add
`:skip_after_callbacks_if_terminated`
option.
*
Add html_escape_once to ERB::Util, and delegate escape_once tag helper to it.
*Carlos Antonio da Silva*
*
Add html_escape_once to ERB::Util, and delegate escape_once tag helper to it.
*Carlos Antonio da Silva*
*
Remove ActiveSupport::TestCase#pending method, use
`skip`
instead.
*Carlos Antonio da Silva*
*
Remove ActiveSupport::TestCase#pending method, use
`skip`
instead.
*Carlos Antonio da Silva*
...
...
activesupport/lib/active_support/callbacks.rb
浏览文件 @
b41ef0a4
...
@@ -169,7 +169,7 @@ def apply(code, key=nil, object=nil)
...
@@ -169,7 +169,7 @@ def apply(code, key=nil, object=nil)
when
:after
when
:after
<<-
RUBY_EVAL
<<-
RUBY_EVAL
#{
code
}
#{
code
}
if
#{
@compiled_options
}
if
#{
!
chain
.
config
[
:skip_after_callbacks_if_terminated
]
||
"!halted"
}
&&
#{
@compiled_options
}
#{
@filter
}
#{
@filter
}
end
end
RUBY_EVAL
RUBY_EVAL
...
@@ -528,6 +528,11 @@ def reset_callbacks(symbol)
...
@@ -528,6 +528,11 @@ def reset_callbacks(symbol)
# other callbacks are not executed. Defaults to "false", meaning no value
# other callbacks are not executed. Defaults to "false", meaning no value
# halts the chain.
# halts the chain.
#
#
# * <tt>:skip_after_callbacks_if_terminated</tt> - Determines if after callbacks should be terminated
# by the <tt>:terminator</tt> option. By default after callbacks executed no matter
# if callback chain was terminated or not.
# Option makes sence only when <tt>:terminator</tt> option is specified.
#
# * <tt>:rescuable</tt> - By default, after filters are not executed if
# * <tt>:rescuable</tt> - By default, after filters are not executed if
# the given block or a before filter raises an error. By setting this option
# the given block or a before filter raises an error. By setting this option
# to <tt>true</tt> exception raised by given block is stored and after
# to <tt>true</tt> exception raised by given block is stored and after
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录