提交 7644a99d 编写于 作者: A Abdelkader Boudih

Deprecate all *_filter callbacks in favor of *_action callbacks

上级 b8e83ce1
* Allow you to pass `prepend: false` to protect_from_forgery to have the * Deprecate all *_filter callbacks in favor of *_action callbacks.
*Rafael Mendonça França*
* Allow you to pass `prepend: false` to protect_from_forgery to have the
verification callback appended instead of prepended to the chain. verification callback appended instead of prepended to the chain.
This allows you to let the verification step depend on prior callbacks. This allows you to let the verification step depend on prior callbacks.
Example: Example:
......
require 'active_support/deprecation'
module AbstractController module AbstractController
module Callbacks module Callbacks
extend ActiveSupport::Concern extend ActiveSupport::Concern
...@@ -65,7 +67,11 @@ def skip_action_callback(*names) ...@@ -65,7 +67,11 @@ def skip_action_callback(*names)
skip_after_action(*names) skip_after_action(*names)
skip_around_action(*names) skip_around_action(*names)
end end
alias_method :skip_filter, :skip_action_callback
def skip_filter(*names)
ActiveSupport::Deprecation.warn("#{callback}_filter is deprecated and will removed in Rails 5.1. Use #{callback}_action instead.")
skip_action_callback(*names)
end
# Take callback names and an optional callback proc, normalize them, # Take callback names and an optional callback proc, normalize them,
# then call the block with each callback. This allows us to abstract # then call the block with each callback. This allows us to abstract
...@@ -180,14 +186,22 @@ def _insert_callbacks(callbacks, block = nil) ...@@ -180,14 +186,22 @@ def _insert_callbacks(callbacks, block = nil)
set_callback(:process_action, callback, name, options) set_callback(:process_action, callback, name, options)
end end
end end
alias_method :"#{callback}_filter", :"#{callback}_action"
define_method "#{callback}_filter" do |*names, &blk|
ActiveSupport::Deprecation.warn("#{callback}_filter is deprecated and will removed in Rails 5.1. Use #{callback}_action instead.")
send("#{callback}_action", *names, &blk)
end
define_method "prepend_#{callback}_action" do |*names, &blk| define_method "prepend_#{callback}_action" do |*names, &blk|
_insert_callbacks(names, blk) do |name, options| _insert_callbacks(names, blk) do |name, options|
set_callback(:process_action, callback, name, options.merge(:prepend => true)) set_callback(:process_action, callback, name, options.merge(:prepend => true))
end end
end end
alias_method :"prepend_#{callback}_filter", :"prepend_#{callback}_action"
define_method "prepend_#{callback}_filter" do |*names, &blk|
ActiveSupport::Deprecation.warn("prepend_#{callback}_filter is deprecated and will removed in Rails 5.1. Use prepend_#{callback}_action instead.")
send("prepend_#{callback}_action", *names, &blk)
end
# Skip a before, after or around callback. See _insert_callbacks # Skip a before, after or around callback. See _insert_callbacks
# for details on the allowed parameters. # for details on the allowed parameters.
...@@ -196,11 +210,19 @@ def _insert_callbacks(callbacks, block = nil) ...@@ -196,11 +210,19 @@ def _insert_callbacks(callbacks, block = nil)
skip_callback(:process_action, callback, name, options) skip_callback(:process_action, callback, name, options)
end end
end end
alias_method :"skip_#{callback}_filter", :"skip_#{callback}_action"
define_method "skip_#{callback}_filter" do |*names, &blk|
ActiveSupport::Deprecation.warn("skip_#{callback}_filter is deprecated and will removed in Rails 5.1. Use skip_#{callback}_action instead.")
send("skip_#{callback}_action", *names, &blk)
end
# *_action is the same as append_*_action # *_action is the same as append_*_action
alias_method :"append_#{callback}_action", :"#{callback}_action" alias_method :"append_#{callback}_action", :"#{callback}_action"
alias_method :"append_#{callback}_filter", :"#{callback}_action"
define_method "append_#{callback}_filter" do |*names, &blk|
ActiveSupport::Deprecation.warn("append_#{callback}_filter is deprecated and will removed in Rails 5.1. Use append_#{callback}_action instead.")
send("append_#{callback}_action", *names, &blk)
end
end end
end end
end end
......
...@@ -267,9 +267,11 @@ class TestCallbacksWithArgs < ActiveSupport::TestCase ...@@ -267,9 +267,11 @@ class TestCallbacksWithArgs < ActiveSupport::TestCase
end end
class AliasedCallbacks < ControllerWithCallbacks class AliasedCallbacks < ControllerWithCallbacks
before_filter :first ActiveSupport::Deprecation.silence do
after_filter :second before_filter :first
around_filter :aroundz after_filter :second
around_filter :aroundz
end
def first def first
@text = "Hello world" @text = "Hello world"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册