提交 a5688fa9 编写于 作者: C Carl Lerche 提交者: Yehuda Katz + Carl Lerche

Add the ability to prepend filters to new callbacks

上级 760cb633
......@@ -37,6 +37,15 @@ def #{filter}_filter(*names, &blk)
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)
......
......@@ -464,7 +464,9 @@ def self.#{symbol}_callback(*filters, &blk)
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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册