diff options
author | Carl Lerche <carllerche@mac.com> | 2009-05-27 11:02:13 -0700 |
---|---|---|
committer | Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com> | 2009-05-27 16:15:53 -0700 |
commit | a5688fa9073dc8824d98071346e6cd9ae417eb72 (patch) | |
tree | 06ed305c581fb7199207f35e625aa58fe4e53b99 | |
parent | 760cb633396a954b465ec0dd0344915185bddec1 (diff) | |
download | rails-a5688fa9073dc8824d98071346e6cd9ae417eb72.tar.gz rails-a5688fa9073dc8824d98071346e6cd9ae417eb72.tar.bz2 rails-a5688fa9073dc8824d98071346e6cd9ae417eb72.zip |
Add the ability to prepend filters to new callbacks
-rw-r--r-- | actionpack/lib/action_controller/abstract/callbacks.rb | 9 | ||||
-rw-r--r-- | activesupport/lib/active_support/new_callbacks.rb | 4 |
2 files changed, 12 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/abstract/callbacks.rb b/actionpack/lib/action_controller/abstract/callbacks.rb index e4f9dd3112..83dd06bf8b 100644 --- a/actionpack/lib/action_controller/abstract/callbacks.rb +++ b/actionpack/lib/action_controller/abstract/callbacks.rb @@ -37,6 +37,15 @@ module AbstractController end end + def prepend_#{filter}_filter(*names, &blk) + options = names.last.is_a?(Hash) ? names.pop : {} + _normalize_callback_options(options) + names.push(blk) if block_given? + names.each do |name| + process_action_callback(:#{filter}, name, options.merge(:prepend => true)) + end + end + def skip_#{filter}_filter(*names, &blk) options = names.last.is_a?(Hash) ? names.pop : {} _normalize_callback_options(options) diff --git a/activesupport/lib/active_support/new_callbacks.rb b/activesupport/lib/active_support/new_callbacks.rb index b6cbdbb6b0..e9a30b9c35 100644 --- a/activesupport/lib/active_support/new_callbacks.rb +++ b/activesupport/lib/active_support/new_callbacks.rb @@ -464,7 +464,9 @@ module ActiveSupport self._#{symbol}_callbacks.delete_if {|c| c.matches?(type, :#{symbol}, filter)} Callback.new(filter, type, options.dup, self, :#{symbol}) end - self._#{symbol}_callbacks.push(*filters) + options[:prepend] ? + self._#{symbol}_callbacks.unshift(*filters) : + self._#{symbol}_callbacks.push(*filters) _define_runner(:#{symbol}, self._#{symbol}_callbacks.compile(nil, :terminator => _#{symbol}_terminator), options) |