Further cleanup of callbacks
This commit is contained in:
parent
8cae3cd0cf
commit
114e25e735
|
@ -360,8 +360,9 @@ module ActiveSupport
|
||||||
# The _run_save_callbacks method can optionally take a key, which
|
# The _run_save_callbacks method can optionally take a key, which
|
||||||
# will be used to compile an optimized callback method for each
|
# will be used to compile an optimized callback method for each
|
||||||
# key. See #define_callbacks for more information.
|
# key. See #define_callbacks for more information.
|
||||||
def _define_runner(symbol, callbacks)
|
def _define_runner(symbol)
|
||||||
body = callbacks.compile(nil, :terminator => send("_#{symbol}_terminator"))
|
body = send("_#{symbol}_callbacks").
|
||||||
|
compile(nil, :terminator => send("_#{symbol}_terminator"))
|
||||||
|
|
||||||
body, line = <<-RUBY_EVAL, __LINE__
|
body, line = <<-RUBY_EVAL, __LINE__
|
||||||
def _run_#{symbol}_callbacks(key = nil, &blk)
|
def _run_#{symbol}_callbacks(key = nil, &blk)
|
||||||
|
@ -437,9 +438,11 @@ module ActiveSupport
|
||||||
callbacks = send("_#{name}_callbacks")
|
callbacks = send("_#{name}_callbacks")
|
||||||
yield callbacks, type, filters, options if block_given?
|
yield callbacks, type, filters, options if block_given?
|
||||||
|
|
||||||
_define_runner(name, callbacks)
|
_define_runner(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
alias_method :_reset_callbacks, :_update_callbacks
|
||||||
|
|
||||||
def set_callback(name, *filters, &block)
|
def set_callback(name, *filters, &block)
|
||||||
_update_callbacks(name, filters, block) do |callbacks, type, filters, options|
|
_update_callbacks(name, filters, block) do |callbacks, type, filters, options|
|
||||||
filters.map! do |filter|
|
filters.map! do |filter|
|
||||||
|
@ -477,13 +480,7 @@ module ActiveSupport
|
||||||
CallbackChain.new(symbol)
|
CallbackChain.new(symbol)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
_define_runner(symbol)
|
||||||
def self.reset_#{symbol}_callbacks
|
|
||||||
_update_callbacks(:#{symbol})
|
|
||||||
end
|
|
||||||
|
|
||||||
self.set_callback(:#{symbol}, :before)
|
|
||||||
RUBY_EVAL
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue