aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBogdan Gusiev <agresso@gmail.com>2012-06-24 10:30:34 +0300
committerBogdan Gusiev <agresso@gmail.com>2012-06-26 09:21:36 +0300
commit88230b7cf77181c2088cce3314493caa9b3ac1fb (patch)
treead9c79bb1bb14f6f2d11fc0a9c428faab5416e24
parent755d1636107f814c6e0f76e7b3f327b9b4bdcc07 (diff)
downloadrails-88230b7cf77181c2088cce3314493caa9b3ac1fb.tar.gz
rails-88230b7cf77181c2088cce3314493caa9b3ac1fb.tar.bz2
rails-88230b7cf77181c2088cce3314493caa9b3ac1fb.zip
AS::Callbacks: deprecate monkey patch code
Deprecate usage of filter object with #before and #after methods as around callback
l---------actionpack/action_pack_url_generator.rb1
-rw-r--r--actionpack/lib/action_controller/caching/sweeping.rb6
-rw-r--r--actionpack/test/controller/filters_test.rb12
-rw-r--r--activesupport/CHANGELOG.md2
-rw-r--r--activesupport/lib/active_support/callbacks.rb3
5 files changed, 23 insertions, 1 deletions
diff --git a/actionpack/action_pack_url_generator.rb b/actionpack/action_pack_url_generator.rb
new file mode 120000
index 0000000000..0bb3e85e86
--- /dev/null
+++ b/actionpack/action_pack_url_generator.rb
@@ -0,0 +1 @@
+/home/bogdan/makabu/my/benchmarks/action_pack_url_generator.rb \ No newline at end of file
diff --git a/actionpack/lib/action_controller/caching/sweeping.rb b/actionpack/lib/action_controller/caching/sweeping.rb
index cc1fa23935..39da15e26a 100644
--- a/actionpack/lib/action_controller/caching/sweeping.rb
+++ b/actionpack/lib/action_controller/caching/sweeping.rb
@@ -72,6 +72,12 @@ module ActionController #:nodoc:
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)
diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb
index ef7fbca675..b9cb93f0f4 100644
--- a/actionpack/test/controller/filters_test.rb
+++ b/actionpack/test/controller/filters_test.rb
@@ -326,6 +326,12 @@ class FilterTest < ActionController::TestCase
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 @@ class FilterTest < ActionController::TestCase
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
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index 00fcfe2001..87b956e3fc 100644
--- a/activesupport/CHANGELOG.md
+++ b/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*
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 0aa3efbb63..6cc875c69a 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -283,7 +283,8 @@ module ActiveSupport
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