Deprecate all *_filter callbacks in favor of *_action callbacks

This is the continuation of the work started at
9d62e048
上级 cd037783
* Deprecate all *_filter callbacks in favor of *_action callbacks.
*Rafael Mendonça França*
* Fix URL generation with `:trailing_slash` such that it does not add * Fix URL generation with `:trailing_slash` such that it does not add
a trailing slash after `.:format` a trailing slash after `.:format`
......
require 'active_support/deprecation'
module AbstractController module AbstractController
module Callbacks module Callbacks
extend ActiveSupport::Concern extend ActiveSupport::Concern
...@@ -42,21 +44,23 @@ def _normalize_callback_option(options, from, to) # :nodoc: ...@@ -42,21 +44,23 @@ def _normalize_callback_option(options, from, to) # :nodoc:
end end
end end
# Skip before, after, and around action callbacks matching any of the names # Skip before, after, and around action callbacks matching any of the names.
# Aliased as skip_filter.
# #
# ==== Parameters # ==== Parameters
# * <tt>names</tt> - A list of valid names that could be used for # * <tt>names</tt> - A list of valid names that could be used for
# callbacks. Note that skipping uses Ruby equality, so it's # callbacks. Note that skipping uses Ruby equality, so it's
# impossible to skip a callback defined using an anonymous proc # impossible to skip a callback defined using an anonymous proc
# using #skip_filter # using #skip_action_callback
def skip_action_callback(*names) def skip_action_callback(*names)
skip_before_action(*names) skip_before_action(*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. 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
...@@ -85,7 +89,6 @@ def _insert_callbacks(callbacks, block = nil) ...@@ -85,7 +89,6 @@ def _insert_callbacks(callbacks, block = nil)
# :call-seq: before_action(names, block) # :call-seq: before_action(names, block)
# #
# Append a callback before actions. See _insert_callbacks for parameter details. # Append a callback before actions. See _insert_callbacks for parameter details.
# Aliased as before_filter.
## ##
# :method: prepend_before_action # :method: prepend_before_action
...@@ -93,7 +96,6 @@ def _insert_callbacks(callbacks, block = nil) ...@@ -93,7 +96,6 @@ def _insert_callbacks(callbacks, block = nil)
# :call-seq: prepend_before_action(names, block) # :call-seq: prepend_before_action(names, block)
# #
# Prepend a callback before actions. See _insert_callbacks for parameter details. # Prepend a callback before actions. See _insert_callbacks for parameter details.
# Aliased as prepend_before_filter.
## ##
# :method: skip_before_action # :method: skip_before_action
...@@ -101,7 +103,6 @@ def _insert_callbacks(callbacks, block = nil) ...@@ -101,7 +103,6 @@ def _insert_callbacks(callbacks, block = nil)
# :call-seq: skip_before_action(names) # :call-seq: skip_before_action(names)
# #
# Skip a callback before actions. See _insert_callbacks for parameter details. # Skip a callback before actions. See _insert_callbacks for parameter details.
# Aliased as skip_before_filter.
## ##
# :method: append_before_action # :method: append_before_action
...@@ -109,7 +110,6 @@ def _insert_callbacks(callbacks, block = nil) ...@@ -109,7 +110,6 @@ def _insert_callbacks(callbacks, block = nil)
# :call-seq: append_before_action(names, block) # :call-seq: append_before_action(names, block)
# #
# Append a callback before actions. See _insert_callbacks for parameter details. # Append a callback before actions. See _insert_callbacks for parameter details.
# Aliased as append_before_filter.
## ##
# :method: after_action # :method: after_action
...@@ -117,7 +117,6 @@ def _insert_callbacks(callbacks, block = nil) ...@@ -117,7 +117,6 @@ def _insert_callbacks(callbacks, block = nil)
# :call-seq: after_action(names, block) # :call-seq: after_action(names, block)
# #
# Append a callback after actions. See _insert_callbacks for parameter details. # Append a callback after actions. See _insert_callbacks for parameter details.
# Aliased as after_filter.
## ##
# :method: prepend_after_action # :method: prepend_after_action
...@@ -125,7 +124,6 @@ def _insert_callbacks(callbacks, block = nil) ...@@ -125,7 +124,6 @@ def _insert_callbacks(callbacks, block = nil)
# :call-seq: prepend_after_action(names, block) # :call-seq: prepend_after_action(names, block)
# #
# Prepend a callback after actions. See _insert_callbacks for parameter details. # Prepend a callback after actions. See _insert_callbacks for parameter details.
# Aliased as prepend_after_filter.
## ##
# :method: skip_after_action # :method: skip_after_action
...@@ -133,7 +131,6 @@ def _insert_callbacks(callbacks, block = nil) ...@@ -133,7 +131,6 @@ def _insert_callbacks(callbacks, block = nil)
# :call-seq: skip_after_action(names) # :call-seq: skip_after_action(names)
# #
# Skip a callback after actions. See _insert_callbacks for parameter details. # Skip a callback after actions. See _insert_callbacks for parameter details.
# Aliased as skip_after_filter.
## ##
# :method: append_after_action # :method: append_after_action
...@@ -141,7 +138,6 @@ def _insert_callbacks(callbacks, block = nil) ...@@ -141,7 +138,6 @@ def _insert_callbacks(callbacks, block = nil)
# :call-seq: append_after_action(names, block) # :call-seq: append_after_action(names, block)
# #
# Append a callback after actions. See _insert_callbacks for parameter details. # Append a callback after actions. See _insert_callbacks for parameter details.
# Aliased as append_after_filter.
## ##
# :method: around_action # :method: around_action
...@@ -149,7 +145,6 @@ def _insert_callbacks(callbacks, block = nil) ...@@ -149,7 +145,6 @@ def _insert_callbacks(callbacks, block = nil)
# :call-seq: around_action(names, block) # :call-seq: around_action(names, block)
# #
# Append a callback around actions. See _insert_callbacks for parameter details. # Append a callback around actions. See _insert_callbacks for parameter details.
# Aliased as around_filter.
## ##
# :method: prepend_around_action # :method: prepend_around_action
...@@ -157,7 +152,6 @@ def _insert_callbacks(callbacks, block = nil) ...@@ -157,7 +152,6 @@ def _insert_callbacks(callbacks, block = nil)
# :call-seq: prepend_around_action(names, block) # :call-seq: prepend_around_action(names, block)
# #
# Prepend a callback around actions. See _insert_callbacks for parameter details. # Prepend a callback around actions. See _insert_callbacks for parameter details.
# Aliased as prepend_around_filter.
## ##
# :method: skip_around_action # :method: skip_around_action
...@@ -165,7 +159,6 @@ def _insert_callbacks(callbacks, block = nil) ...@@ -165,7 +159,6 @@ def _insert_callbacks(callbacks, block = nil)
# :call-seq: skip_around_action(names) # :call-seq: skip_around_action(names)
# #
# Skip a callback around actions. See _insert_callbacks for parameter details. # Skip a callback around actions. See _insert_callbacks for parameter details.
# Aliased as skip_around_filter.
## ##
# :method: append_around_action # :method: append_around_action
...@@ -173,7 +166,6 @@ def _insert_callbacks(callbacks, block = nil) ...@@ -173,7 +166,6 @@ def _insert_callbacks(callbacks, block = nil)
# :call-seq: append_around_action(names, block) # :call-seq: append_around_action(names, block)
# #
# Append a callback around actions. See _insert_callbacks for parameter details. # Append a callback around actions. See _insert_callbacks for parameter details.
# Aliased as append_around_filter.
# set up before_action, prepend_before_action, skip_before_action, etc. # set up before_action, prepend_before_action, skip_before_action, etc.
# for each of before, after, and around. # for each of before, after, and around.
...@@ -184,7 +176,10 @@ def _insert_callbacks(callbacks, block = nil) ...@@ -184,7 +176,10 @@ def _insert_callbacks(callbacks, block = nil)
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. 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|
...@@ -192,7 +187,10 @@ def _insert_callbacks(callbacks, block = nil) ...@@ -192,7 +187,10 @@ def _insert_callbacks(callbacks, block = nil)
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. 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.
...@@ -202,11 +200,17 @@ def _insert_callbacks(callbacks, block = nil) ...@@ -202,11 +200,17 @@ def _insert_callbacks(callbacks, block = nil)
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. 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_before_action, :before_action alias_method :"append_#{callback}_action", :"#{callback}_action" # alias_method :append_before_action, :before_action
alias_method :"append_#{callback}_filter", :"#{callback}_action" # alias_method :append_before_filter, :before_action define_method "append_#{callback}_filter" do |*names, &blk|
ActiveSupport::Deprecation.warn("append_#{callback}_filter is deprecated and will removed in Rails 5. 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"
......
...@@ -164,7 +164,7 @@ def view_assigns ...@@ -164,7 +164,7 @@ def view_assigns
end end
class DefaultUrlOptionsCachingController < ActionController::Base class DefaultUrlOptionsCachingController < ActionController::Base
before_filter { @dynamic_opt = 'opt' } before_action { @dynamic_opt = 'opt' }
def test_url_options_reset def test_url_options_reset
render text: url_for(params) render text: url_for(params)
......
...@@ -5,7 +5,7 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc: ...@@ -5,7 +5,7 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc:
prepend_view_path ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH prepend_view_path ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH
layout -> { request.xhr? ? false : 'application' } layout -> { request.xhr? ? false : 'application' }
before_filter :require_local! before_action :require_local!
def index def index
redirect_to action: :routes redirect_to action: :routes
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
class Rails::MailersController < Rails::ApplicationController # :nodoc: class Rails::MailersController < Rails::ApplicationController # :nodoc:
prepend_view_path ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH prepend_view_path ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH
before_filter :require_local! before_action :require_local!
before_filter :find_preview, only: :preview before_action :find_preview, only: :preview
def index def index
@previews = ActionMailer::Preview.all @previews = ActionMailer::Preview.all
...@@ -70,4 +70,4 @@ def find_part(format) ...@@ -70,4 +70,4 @@ def find_part(format)
@email @email
end end
end end
end end
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册