Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

AS::Callbacks: deprecate monkey patch code

Deprecate usage of filter object with #before and #after
methods as around callback
  • Loading branch information...
commit 88230b7cf77181c2088cce3314493caa9b3ac1fb 1 parent 755d163
@bogdan bogdan authored
View
1  actionpack/action_pack_url_generator.rb
View
6 actionpack/lib/action_controller/caching/sweeping.rb
@@ -72,6 +72,12 @@ def after(controller)
self.controller = nil
end
+ def around(controller)
+ before(controller)
+ yield
+ after(controller)
+ end
+
protected
# gets the action cache path for the given options.
def action_path_for(options)
View
12 actionpack/test/controller/filters_test.rb
@@ -326,6 +326,12 @@ def after(controller)
controller.instance_variable_set(:"@after_ran", true)
controller.class.execution_log << " after aroundfilter " if controller.respond_to? :execution_log
end
+
+ def around(controller)
+ before(controller)
+ yield
+ after(controller)
+ end
end
class AppendedAroundFilter
@@ -336,6 +342,12 @@ def before(controller)
def after(controller)
controller.class.execution_log << " after appended aroundfilter "
end
+
+ def around(controller)
+ before(controller)
+ yield
+ after(controller)
+ end
end
class AuditController < ActionController::Base
View
2  activesupport/CHANGELOG.md
@@ -1,5 +1,7 @@
## Rails 4.0.0 (unreleased) ##
+* AS::Callbacks: deprecate usage of filter object with `#before` and `#after` methods as `around` callback. *Bogdan Gusiev*
+
* Add `Time#prev_quarter' and 'Time#next_quarter' short-hands for months_ago(3) and months_since(3). *SungHee Kang*
* Remove obsolete and unused `require_association` method from dependencies. *fxn*
View
3  activesupport/lib/active_support/callbacks.rb
@@ -283,7 +283,8 @@ def _normalize_legacy_filter(kind, filter)
filter.singleton_class.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
def #{kind}(context, &block) filter(context, &block) end
RUBY_EVAL
- elsif filter.respond_to?(:before) && filter.respond_to?(:after) && kind == :around
+ elsif filter.respond_to?(:before) && filter.respond_to?(:after) && kind == :around && !filter.respond_to?(:around)
+ ActiveSupport::Deprecation.warn("Filter object with #before and #after methods is deprecated. Define #around method instead.")
def filter.around(context)
should_continue = before(context)
yield if should_continue
Please sign in to comment.
Something went wrong with that request. Please try again.