From 114e25e7359a76e07114f9914a0fb9baecc67644 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Tue, 2 Jun 2009 22:35:28 -0700 Subject: [PATCH] Further cleanup of callbacks --- .../lib/active_support/new_callbacks.rb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/activesupport/lib/active_support/new_callbacks.rb b/activesupport/lib/active_support/new_callbacks.rb index 0fe3ee4bad..bc340fccec 100644 --- a/activesupport/lib/active_support/new_callbacks.rb +++ b/activesupport/lib/active_support/new_callbacks.rb @@ -360,8 +360,9 @@ module ActiveSupport # The _run_save_callbacks method can optionally take a key, which # will be used to compile an optimized callback method for each # key. See #define_callbacks for more information. - def _define_runner(symbol, callbacks) - body = callbacks.compile(nil, :terminator => send("_#{symbol}_terminator")) + def _define_runner(symbol) + body = send("_#{symbol}_callbacks"). + compile(nil, :terminator => send("_#{symbol}_terminator")) body, line = <<-RUBY_EVAL, __LINE__ def _run_#{symbol}_callbacks(key = nil, &blk) @@ -437,9 +438,11 @@ module ActiveSupport callbacks = send("_#{name}_callbacks") yield callbacks, type, filters, options if block_given? - _define_runner(name, callbacks) + _define_runner(name) end + alias_method :_reset_callbacks, :_update_callbacks + def set_callback(name, *filters, &block) _update_callbacks(name, filters, block) do |callbacks, type, filters, options| filters.map! do |filter| @@ -477,13 +480,7 @@ module ActiveSupport CallbackChain.new(symbol) end - self.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 - def self.reset_#{symbol}_callbacks - _update_callbacks(:#{symbol}) - end - - self.set_callback(:#{symbol}, :before) - RUBY_EVAL + _define_runner(symbol) end end end