mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
AS::Callbacks: deprecate monkey patch code
Deprecate usage of filter object with #before and #after methods as around callback
This commit is contained in:
parent
755d163610
commit
88230b7cf7
5 changed files with 23 additions and 1 deletions
1
actionpack/action_pack_url_generator.rb
Symbolic link
1
actionpack/action_pack_url_generator.rb
Symbolic link
|
@ -0,0 +1 @@
|
|||
/home/bogdan/makabu/my/benchmarks/action_pack_url_generator.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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 @@ 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
|
||||
|
|
Loading…
Reference in a new issue