lib/active_support/callbacks.rb in activesupport-3.0.0.rc vs lib/active_support/callbacks.rb in activesupport-3.0.0.rc2
- old
+ new
@@ -91,10 +91,15 @@
def run_callbacks(kind, *args, &block)
send("_run_#{kind}_callbacks", *args, &block)
end
+ def callback(kind)
+ ActiveSupport::Deprecation.warn("callback is deprecated. Please use run_callbacks")
+ send("_run_#{kind}_callbacks")
+ end
+
class Callback
@@_callback_sequence = 0
attr_accessor :chain, :filter, :kind, :options, :per_key, :klass, :raw_filter
@@ -417,11 +422,14 @@
#
def __create_keyed_callback(name, kind, object, &blk) #:nodoc:
@_keyed_callbacks ||= {}
@_keyed_callbacks[name] ||= begin
str = send("_#{kind}_callbacks").compile(name, object)
- class_eval "def #{name}() #{str} end", __FILE__, __LINE__
+ class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
+ def #{name}() #{str} end
+ protected :#{name}
+ RUBY_EVAL
true
end
end
# This is used internally to append, prepend and skip callbacks to the
@@ -474,11 +482,11 @@
mapped ||= filters.map do |filter|
Callback.new(chain, filter, type, options.dup, self)
end
filters.each do |filter|
- chain.delete_if {|c| c.matches?(type, filter) }
+ chain.delete_if {|c| c.matches?(type, filter) }
end
options[:prepend] ? chain.unshift(*mapped) : chain.push(*mapped)
end
end
@@ -566,10 +574,12 @@
#
# define_callbacks :save, :scope => [:kind, :name]
#
# would trigger <tt>Audit#before_save</tt> instead. That's constructed by calling
# <tt>"#{kind}_#{name}"</tt> on the given instance. In this case "kind" is "before" and
- # "name" is "save".
+ # "name" is "save". In this context ":kind" and ":name" have special meanings: ":kind"
+ # refers to the kind of callback (before/after/around) and ":name" refers to the
+ # method on which callbacks are being defined.
#
# A declaration like
#
# define_callbacks :save, :scope => [:name]
#