Add the ability to prepend filters to new callbacks

This commit is contained in:
Carl Lerche 2009-05-27 11:02:13 -07:00 committed by Yehuda Katz + Carl Lerche
parent 760cb63339
commit a5688fa907
2 changed files with 12 additions and 1 deletions

View File

@ -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)

View File

@ -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)