Permalink
Browse files

AS::Callbacks: deprecate monkey patch code

Deprecate usage of filter object with #before and #after
methods as around callback
  • Loading branch information...
1 parent 755d163 commit 88230b7cf77181c2088cce3314493caa9b3ac1fb @bogdan bogdan committed Jun 24, 2012
@@ -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)
@@ -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
@@ -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*
@@ -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

0 comments on commit 88230b7

Please sign in to comment.