Module: ActiveSupport::Callbacks::ClassMethods

Defined in:
lib/active_support/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#define_callbacks(*callbacks) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/active_support/callbacks.rb', line 210

def define_callbacks(*callbacks)
  callbacks.each do |callback|
    class_eval <<-"end_eval"
      def self.#{callback}(*methods, &block)
        callbacks = CallbackChain.build(:#{callback}, *methods, &block)
        (@#{callback}_callbacks ||= CallbackChain.new).concat callbacks
      end

      def self.#{callback}_callback_chain
        @#{callback}_callbacks ||= CallbackChain.new

        if superclass.respond_to?(:#{callback}_callback_chain)
          CallbackChain.new(superclass.#{callback}_callback_chain + @#{callback}_callbacks)
        else
          @#{callback}_callbacks
        end
      end
    end_eval
  end
end