aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@plataformatec.com.br>2012-02-04 03:55:53 -0800
committerJosé Valim <jose.valim@plataformatec.com.br>2012-02-04 03:55:53 -0800
commitef32b5938442a87e9d3addc53448a6949f23f349 (patch)
tree310470ae2bc89dec4e81f1db3e49ec16cf5410f7 /activesupport/lib
parent42e3b6396f8c6f156ea4d6fdef341dfc074724cd (diff)
parent4f53091dd199915e0605e8202e7534c0edcaf3fa (diff)
downloadrails-ef32b5938442a87e9d3addc53448a6949f23f349.tar.gz
rails-ef32b5938442a87e9d3addc53448a6949f23f349.tar.bz2
rails-ef32b5938442a87e9d3addc53448a6949f23f349.zip
Merge pull request #4877 from bogdan/drop_per_key
AS::Callbacks: rip out per_key option.
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/callbacks.rb47
1 files changed, 13 insertions, 34 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 3091a36fa0..c189d94de3 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -95,6 +95,7 @@ module ActiveSupport
def initialize(chain, filter, kind, options, klass)
@chain, @kind, @klass = chain, kind, klass
+ deprecate_per_key_option(options)
normalize_options!(options)
@raw_filter, @options = filter, options
@@ -103,6 +104,12 @@ module ActiveSupport
@callback_id = next_id
end
+ def deprecate_per_key_option(options)
+ if options[:per_key]
+ raise NotImplementedError, ":per_key option is no longer supported. Use generic :if and :unless options instead."
+ end
+ end
+
def clone(chain, klass)
obj = super()
obj.chain = chain
@@ -116,11 +123,6 @@ module ActiveSupport
def normalize_options!(options)
options[:if] = Array(options[:if])
options[:unless] = Array(options[:unless])
-
- options[:per_key] ||= {}
-
- options[:if] += Array(options[:per_key][:if])
- options[:unless] += Array(options[:per_key][:unless])
end
def name
@@ -140,9 +142,9 @@ module ActiveSupport
filter_options[:unless].concat(Array(new_options[:if])) if new_options.key?(:if)
end
- def recompile!(_options, _per_key)
+ def recompile!(_options)
+ deprecate_per_key_option(_options)
_update_filter(self.options, _options)
- _update_filter(self.options, _per_key)
@callback_id = next_id
@filter = _compile_filter(@raw_filter)
@@ -352,9 +354,9 @@ module ActiveSupport
module ClassMethods
- # This method calls the callback method for the given key.
- # If this called first time it creates a new callback method for the key,
- # calculating which callbacks can be omitted because of per_key conditions.
+ # This method runs callback chain for the given key.
+ # If this called first time it creates a new callback method for the key.
+ # This generated method plays caching role.
#
def __run_callbacks(key, kind, object, &blk) #:nodoc:
name = __callback_runner_name(kind)
@@ -427,29 +429,6 @@ module ActiveSupport
# will be called only when it returns a false value.
# * <tt>:prepend</tt> - If true, the callback will be prepended to the existing
# chain rather than appended.
- # * <tt>:per_key</tt> - A hash with <tt>:if</tt> and <tt>:unless</tt> options;
- # see "Per-key conditions" below.
- #
- # ===== Per-key conditions
- #
- # When creating or skipping callbacks, you can specify conditions that
- # are always the same for a given key. For instance, in Action Pack,
- # we convert :only and :except conditions into per-key conditions.
- #
- # before_filter :authenticate, :except => "index"
- #
- # becomes
- #
- # set_callback :process_action, :before, :authenticate, :per_key => {:unless => proc {|c| c.action_name == "index"}}
- #
- # Per-key conditions are evaluated only once per use of a given key.
- # In the case of the above example, you would do:
- #
- # run_callbacks(:process_action, action_name) { ... dispatch stuff ... }
- #
- # In that case, each action_name would get its own compiled callback
- # method that took into consideration the per_key conditions. This
- # is a speed improvement for ActionPack.
#
def set_callback(name, *filter_list, &block)
mapped = nil
@@ -484,7 +463,7 @@ module ActiveSupport
if filter && options.any?
new_filter = filter.clone(chain, self)
chain.insert(chain.index(filter), new_filter)
- new_filter.recompile!(options, options[:per_key] || {})
+ new_filter.recompile!(options)
end
chain.delete(filter)