diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-03-18 17:56:05 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-03-18 17:56:05 +0000 |
commit | 856a4dcf1207e888b23016cac6a64582051aa0ff (patch) | |
tree | 6ab4bf4149122d70f457e597bf4dc5e4defe5629 /activerecord | |
parent | 9af9fc3da19fb06e965d977339bfb79ab014bcb7 (diff) | |
download | rails-856a4dcf1207e888b23016cac6a64582051aa0ff.tar.gz rails-856a4dcf1207e888b23016cac6a64582051aa0ff.tar.bz2 rails-856a4dcf1207e888b23016cac6a64582051aa0ff.zip |
Refactor filters to use Active Support callbacks. Closes #11235.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9055 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rwxr-xr-x | activerecord/lib/active_record/validations.rb | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index f9888c7111..7775cf93c5 100755 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -282,19 +282,20 @@ module ActiveRecord base.send :include, ActiveSupport::Callbacks - # TODO: Use helper ActiveSupport::Callbacks#define_callbacks instead - %w( validate validate_on_create validate_on_update ).each do |validation_method| + VALIDATIONS.each do |validation_method| base.class_eval <<-"end_eval" def self.#{validation_method}(*methods, &block) - options = methods.extract_options! - methods << block if block_given? - methods.map! { |method| Callback.new(:#{validation_method}, method, options) } - existing_methods = read_inheritable_attribute(:#{validation_method}) || [] - write_inheritable_attribute(:#{validation_method}, existing_methods | methods) + methods = CallbackChain.build(:#{validation_method}, *methods, &block) + self.#{validation_method}_callback_chain.replace(#{validation_method}_callback_chain | methods) end def self.#{validation_method}_callback_chain - read_inheritable_attribute(:#{validation_method}) || [] + if chain = read_inheritable_attribute(:#{validation_method}) + return chain + else + write_inheritable_attribute(:#{validation_method}, CallbackChain.new) + return #{validation_method}_callback_chain + end end end_eval end |