Skip to content

Commit 7644a99

Browse files
committed
Deprecate all *_filter callbacks in favor of *_action callbacks
1 parent b8e83ce commit 7644a99

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

actionpack/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
* Allow you to pass `prepend: false` to protect_from_forgery to have the
1+
* Deprecate all *_filter callbacks in favor of *_action callbacks.
2+
3+
*Rafael Mendonça França*
4+
5+
* Allow you to pass `prepend: false` to protect_from_forgery to have the
26
verification callback appended instead of prepended to the chain.
37
This allows you to let the verification step depend on prior callbacks.
48
Example:

actionpack/lib/abstract_controller/callbacks.rb

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'active_support/deprecation'
2+
13
module AbstractController
24
module Callbacks
35
extend ActiveSupport::Concern
@@ -65,7 +67,11 @@ def skip_action_callback(*names)
6567
skip_after_action(*names)
6668
skip_around_action(*names)
6769
end
68-
alias_method :skip_filter, :skip_action_callback
70+
71+
def skip_filter(*names)
72+
ActiveSupport::Deprecation.warn("#{callback}_filter is deprecated and will removed in Rails 5.1. Use #{callback}_action instead.")
73+
skip_action_callback(*names)
74+
end
6975

7076
# Take callback names and an optional callback proc, normalize them,
7177
# then call the block with each callback. This allows us to abstract
@@ -180,14 +186,22 @@ def _insert_callbacks(callbacks, block = nil)
180186
set_callback(:process_action, callback, name, options)
181187
end
182188
end
183-
alias_method :"#{callback}_filter", :"#{callback}_action"
189+
190+
define_method "#{callback}_filter" do |*names, &blk|
191+
ActiveSupport::Deprecation.warn("#{callback}_filter is deprecated and will removed in Rails 5.1. Use #{callback}_action instead.")
192+
send("#{callback}_action", *names, &blk)
193+
end
184194

185195
define_method "prepend_#{callback}_action" do |*names, &blk|
186196
_insert_callbacks(names, blk) do |name, options|
187197
set_callback(:process_action, callback, name, options.merge(:prepend => true))
188198
end
189199
end
190-
alias_method :"prepend_#{callback}_filter", :"prepend_#{callback}_action"
200+
201+
define_method "prepend_#{callback}_filter" do |*names, &blk|
202+
ActiveSupport::Deprecation.warn("prepend_#{callback}_filter is deprecated and will removed in Rails 5.1. Use prepend_#{callback}_action instead.")
203+
send("prepend_#{callback}_action", *names, &blk)
204+
end
191205

192206
# Skip a before, after or around callback. See _insert_callbacks
193207
# for details on the allowed parameters.
@@ -196,11 +210,19 @@ def _insert_callbacks(callbacks, block = nil)
196210
skip_callback(:process_action, callback, name, options)
197211
end
198212
end
199-
alias_method :"skip_#{callback}_filter", :"skip_#{callback}_action"
213+
214+
define_method "skip_#{callback}_filter" do |*names, &blk|
215+
ActiveSupport::Deprecation.warn("skip_#{callback}_filter is deprecated and will removed in Rails 5.1. Use skip_#{callback}_action instead.")
216+
send("skip_#{callback}_action", *names, &blk)
217+
end
200218

201219
# *_action is the same as append_*_action
202220
alias_method :"append_#{callback}_action", :"#{callback}_action"
203-
alias_method :"append_#{callback}_filter", :"#{callback}_action"
221+
222+
define_method "append_#{callback}_filter" do |*names, &blk|
223+
ActiveSupport::Deprecation.warn("append_#{callback}_filter is deprecated and will removed in Rails 5.1. Use append_#{callback}_action instead.")
224+
send("append_#{callback}_action", *names, &blk)
225+
end
204226
end
205227
end
206228
end

actionpack/test/abstract/callbacks_test.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,11 @@ class TestCallbacksWithArgs < ActiveSupport::TestCase
267267
end
268268

269269
class AliasedCallbacks < ControllerWithCallbacks
270-
before_filter :first
271-
after_filter :second
272-
around_filter :aroundz
270+
ActiveSupport::Deprecation.silence do
271+
before_filter :first
272+
after_filter :second
273+
around_filter :aroundz
274+
end
273275

274276
def first
275277
@text = "Hello world"

0 commit comments

Comments
 (0)