Skip to content

Commit 6c5f43b

Browse files
committed
Deprecate all *_filter callbacks in favor of *_action callbacks
This is the continuation of the work started at 9d62e04
1 parent cd03778 commit 6c5f43b

File tree

7 files changed

+228
-218
lines changed

7 files changed

+228
-218
lines changed

actionpack/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Deprecate all *_filter callbacks in favor of *_action callbacks.
2+
3+
*Rafael Mendonça França*
4+
15
* Fix URL generation with `:trailing_slash` such that it does not add
26
a trailing slash after `.:format`
37

actionpack/lib/abstract_controller/callbacks.rb

Lines changed: 24 additions & 20 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
@@ -42,21 +44,23 @@ def _normalize_callback_option(options, from, to) # :nodoc:
4244
end
4345
end
4446

45-
# Skip before, after, and around action callbacks matching any of the names
46-
# Aliased as skip_filter.
47+
# Skip before, after, and around action callbacks matching any of the names.
4748
#
4849
# ==== Parameters
4950
# * <tt>names</tt> - A list of valid names that could be used for
5051
# callbacks. Note that skipping uses Ruby equality, so it's
5152
# impossible to skip a callback defined using an anonymous proc
52-
# using #skip_filter
53+
# using #skip_action_callback
5354
def skip_action_callback(*names)
5455
skip_before_action(*names)
5556
skip_after_action(*names)
5657
skip_around_action(*names)
5758
end
5859

59-
alias_method :skip_filter, :skip_action_callback
60+
def skip_filter(*names)
61+
ActiveSupport::Deprecation.warn("#{callback}_filter is deprecated and will removed in Rails 5. Use #{callback}_action instead.")
62+
skip_action_callback(*names)
63+
end
6064

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

9093
##
9194
# :method: prepend_before_action
9295
#
9396
# :call-seq: prepend_before_action(names, block)
9497
#
9598
# Prepend a callback before actions. See _insert_callbacks for parameter details.
96-
# Aliased as prepend_before_filter.
9799

98100
##
99101
# :method: skip_before_action
100102
#
101103
# :call-seq: skip_before_action(names)
102104
#
103105
# Skip a callback before actions. See _insert_callbacks for parameter details.
104-
# Aliased as skip_before_filter.
105106

106107
##
107108
# :method: append_before_action
108109
#
109110
# :call-seq: append_before_action(names, block)
110111
#
111112
# Append a callback before actions. See _insert_callbacks for parameter details.
112-
# Aliased as append_before_filter.
113113

114114
##
115115
# :method: after_action
116116
#
117117
# :call-seq: after_action(names, block)
118118
#
119119
# Append a callback after actions. See _insert_callbacks for parameter details.
120-
# Aliased as after_filter.
121120

122121
##
123122
# :method: prepend_after_action
124123
#
125124
# :call-seq: prepend_after_action(names, block)
126125
#
127126
# Prepend a callback after actions. See _insert_callbacks for parameter details.
128-
# Aliased as prepend_after_filter.
129127

130128
##
131129
# :method: skip_after_action
132130
#
133131
# :call-seq: skip_after_action(names)
134132
#
135133
# Skip a callback after actions. See _insert_callbacks for parameter details.
136-
# Aliased as skip_after_filter.
137134

138135
##
139136
# :method: append_after_action
140137
#
141138
# :call-seq: append_after_action(names, block)
142139
#
143140
# Append a callback after actions. See _insert_callbacks for parameter details.
144-
# Aliased as append_after_filter.
145141

146142
##
147143
# :method: around_action
148144
#
149145
# :call-seq: around_action(names, block)
150146
#
151147
# Append a callback around actions. See _insert_callbacks for parameter details.
152-
# Aliased as around_filter.
153148

154149
##
155150
# :method: prepend_around_action
156151
#
157152
# :call-seq: prepend_around_action(names, block)
158153
#
159154
# Prepend a callback around actions. See _insert_callbacks for parameter details.
160-
# Aliased as prepend_around_filter.
161155

162156
##
163157
# :method: skip_around_action
164158
#
165159
# :call-seq: skip_around_action(names)
166160
#
167161
# Skip a callback around actions. See _insert_callbacks for parameter details.
168-
# Aliased as skip_around_filter.
169162

170163
##
171164
# :method: append_around_action
172165
#
173166
# :call-seq: append_around_action(names, block)
174167
#
175168
# Append a callback around actions. See _insert_callbacks for parameter details.
176-
# Aliased as append_around_filter.
177169

178170
# set up before_action, prepend_before_action, skip_before_action, etc.
179171
# for each of before, after, and around.
@@ -184,15 +176,21 @@ def _insert_callbacks(callbacks, block = nil)
184176
end
185177
end
186178

187-
alias_method :"#{callback}_filter", :"#{callback}_action"
179+
define_method "#{callback}_filter" do |*names, &blk|
180+
ActiveSupport::Deprecation.warn("#{callback}_filter is deprecated and will removed in Rails 5. Use #{callback}_action instead.")
181+
send("#{callback}_action", *names, &blk)
182+
end
188183

189184
define_method "prepend_#{callback}_action" do |*names, &blk|
190185
_insert_callbacks(names, blk) do |name, options|
191186
set_callback(:process_action, callback, name, options.merge(:prepend => true))
192187
end
193188
end
194189

195-
alias_method :"prepend_#{callback}_filter", :"prepend_#{callback}_action"
190+
define_method "prepend_#{callback}_filter" do |*names, &blk|
191+
ActiveSupport::Deprecation.warn("prepend_#{callback}_filter is deprecated and will removed in Rails 5. Use prepend_#{callback}_action instead.")
192+
send("prepend_#{callback}_action", *names, &blk)
193+
end
196194

197195
# Skip a before, after or around callback. See _insert_callbacks
198196
# for details on the allowed parameters.
@@ -202,11 +200,17 @@ def _insert_callbacks(callbacks, block = nil)
202200
end
203201
end
204202

205-
alias_method :"skip_#{callback}_filter", :"skip_#{callback}_action"
203+
define_method "skip_#{callback}_filter" do |*names, &blk|
204+
ActiveSupport::Deprecation.warn("skip_#{callback}_filter is deprecated and will removed in Rails 5. Use skip_#{callback}_action instead.")
205+
send("skip_#{callback}_action", *names, &blk)
206+
end
206207

207208
# *_action is the same as append_*_action
208209
alias_method :"append_#{callback}_action", :"#{callback}_action" # alias_method :append_before_action, :before_action
209-
alias_method :"append_#{callback}_filter", :"#{callback}_action" # alias_method :append_before_filter, :before_action
210+
define_method "append_#{callback}_filter" do |*names, &blk|
211+
ActiveSupport::Deprecation.warn("append_#{callback}_filter is deprecated and will removed in Rails 5. Use append_#{callback}_action instead.")
212+
send("append_#{callback}_action", *names, &blk)
213+
end
210214
end
211215
end
212216
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)