Skip to content
Permalink
Browse files

Deprecate all *_filter callbacks in favor of *_action callbacks

This is the continuation of the work started at
9d62e04
  • Loading branch information
rafaelfranca committed May 27, 2014
1 parent cd03778 commit 6c5f43bab8206747a8591435b2aa0ff7051ad3de
@@ -1,3 +1,7 @@
* 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
a trailing slash after `.:format`

@@ -1,3 +1,5 @@
require 'active_support/deprecation'

module AbstractController
module Callbacks
extend ActiveSupport::Concern
@@ -42,21 +44,23 @@ def _normalize_callback_option(options, from, to) # :nodoc:
end
end

# Skip before, after, and around action callbacks matching any of the names
# Aliased as skip_filter.
# Skip before, after, and around action callbacks matching any of the names.
#
# ==== Parameters
# * <tt>names</tt> - A list of valid names that could be used for
# callbacks. Note that skipping uses Ruby equality, so it's
# impossible to skip a callback defined using an anonymous proc
# using #skip_filter
# using #skip_action_callback
def skip_action_callback(*names)
skip_before_action(*names)
skip_after_action(*names)
skip_around_action(*names)
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.")

This comment has been minimized.

Copy link
@rafacv

rafacv Jun 2, 2014

Contributor

@rafaelfranca Probably I'm missing something, but is callback variable being defined somewhere in the current scope?

This comment has been minimized.

Copy link
@rafaelfranca

rafaelfranca Jun 2, 2014

Author Member

No. it is not. I'll revert this commit in one day or two so it will be fine.

skip_action_callback(*names)
end

# Take callback names and an optional callback proc, normalize them,
# then call the block with each callback. This allows us to abstract
@@ -85,95 +89,83 @@ def _insert_callbacks(callbacks, block = nil)
# :call-seq: before_action(names, block)
#
# Append a callback before actions. See _insert_callbacks for parameter details.
# Aliased as before_filter.

##
# :method: prepend_before_action
#
# :call-seq: prepend_before_action(names, block)
#
# Prepend a callback before actions. See _insert_callbacks for parameter details.
# Aliased as prepend_before_filter.

##
# :method: skip_before_action
#
# :call-seq: skip_before_action(names)
#
# Skip a callback before actions. See _insert_callbacks for parameter details.
# Aliased as skip_before_filter.

##
# :method: append_before_action
#
# :call-seq: append_before_action(names, block)
#
# Append a callback before actions. See _insert_callbacks for parameter details.
# Aliased as append_before_filter.

##
# :method: after_action
#
# :call-seq: after_action(names, block)
#
# Append a callback after actions. See _insert_callbacks for parameter details.
# Aliased as after_filter.

##
# :method: prepend_after_action
#
# :call-seq: prepend_after_action(names, block)
#
# Prepend a callback after actions. See _insert_callbacks for parameter details.
# Aliased as prepend_after_filter.

##
# :method: skip_after_action
#
# :call-seq: skip_after_action(names)
#
# Skip a callback after actions. See _insert_callbacks for parameter details.
# Aliased as skip_after_filter.

##
# :method: append_after_action
#
# :call-seq: append_after_action(names, block)
#
# Append a callback after actions. See _insert_callbacks for parameter details.
# Aliased as append_after_filter.

##
# :method: around_action
#
# :call-seq: around_action(names, block)
#
# Append a callback around actions. See _insert_callbacks for parameter details.
# Aliased as around_filter.

##
# :method: prepend_around_action
#
# :call-seq: prepend_around_action(names, block)
#
# Prepend a callback around actions. See _insert_callbacks for parameter details.
# Aliased as prepend_around_filter.

##
# :method: skip_around_action
#
# :call-seq: skip_around_action(names)
#
# Skip a callback around actions. See _insert_callbacks for parameter details.
# Aliased as skip_around_filter.

##
# :method: append_around_action
#
# :call-seq: append_around_action(names, block)
#
# 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.
# for each of before, after, and around.
@@ -184,15 +176,21 @@ def _insert_callbacks(callbacks, block = nil)
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|
_insert_callbacks(names, blk) do |name, options|
set_callback(:process_action, callback, name, options.merge(:prepend => true))
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
# for details on the allowed parameters.
@@ -202,11 +200,17 @@ def _insert_callbacks(callbacks, block = nil)
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
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
@@ -267,9 +267,11 @@ class TestCallbacksWithArgs < ActiveSupport::TestCase
end

class AliasedCallbacks < ControllerWithCallbacks
before_filter :first
after_filter :second
around_filter :aroundz
ActiveSupport::Deprecation.silence do
before_filter :first
after_filter :second
around_filter :aroundz
end

def first
@text = "Hello world"

2 comments on commit 6c5f43b

@egilburg

This comment has been minimized.

Copy link
Contributor

@egilburg egilburg replied Jul 14, 2014

Is this just name change it does it change to behave like model callbacks (e.g. stop chain on false return from before_action)? Current before_filter only stops on raise or render, not on basic false return.

@rafaelfranca

This comment has been minimized.

Copy link
Member Author

@rafaelfranca rafaelfranca replied Jul 14, 2014

Please sign in to comment.
You can’t perform that action at this time.