-
Notifications
You must be signed in to change notification settings - Fork 21.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate all *_filter callbacks in favor of *_action callbacks
This is the continuation of the work started at 9d62e04
- Loading branch information
1 parent
cd03778
commit 6c5f43b
Showing
7 changed files
with
228 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rafaelfranca
Author
Member
|
||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
2 comments
on commit 6c5f43b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is only a name change
On Sunday, July 13, 2014, Eugene Gilburg ***@***.*** wrote:
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.
—
Reply to this email directly or view it on GitHub
6c5f43b#commitcomment-6989876
.
##
Rafael Mendonça França
http://twitter.com/rafaelfranca
https://github.com/rafaelfranca
@rafaelfranca Probably I'm missing something, but is
callback
variable being defined somewhere in the current scope?