aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/validations.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-04-20 11:45:44 -0500
committerJoshua Peek <josh@joshpeek.com>2008-04-20 11:45:44 -0500
commit46ab7422d9ebac0d529f71a3a7c2feaf0b9d5dbd (patch)
treeb8b28b08ced54f68137f43d796db00ffd8205b89 /activerecord/lib/active_record/validations.rb
parent14a40804a29a57ad05ca6bffbe1e5334089593a9 (diff)
downloadrails-46ab7422d9ebac0d529f71a3a7c2feaf0b9d5dbd.tar.gz
rails-46ab7422d9ebac0d529f71a3a7c2feaf0b9d5dbd.tar.bz2
rails-46ab7422d9ebac0d529f71a3a7c2feaf0b9d5dbd.zip
Use define_callbacks helper for ActiveRecord validations.
Diffstat (limited to 'activerecord/lib/active_record/validations.rb')
-rwxr-xr-xactiverecord/lib/active_record/validations.rb26
1 files changed, 5 insertions, 21 deletions
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb
index 7b70f78405..1d12ea8ad7 100755
--- a/activerecord/lib/active_record/validations.rb
+++ b/activerecord/lib/active_record/validations.rb
@@ -281,23 +281,7 @@ module ActiveRecord
end
base.send :include, ActiveSupport::Callbacks
-
- VALIDATIONS.each do |validation_method|
- base.class_eval <<-"end_eval"
- def self.#{validation_method}(*methods, &block)
- self.#{validation_method}_callback_chain | CallbackChain.build(:#{validation_method}, *methods, &block)
- end
-
- def self.#{validation_method}_callback_chain
- 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
+ base.define_callbacks *VALIDATIONS
end
# All of the following validations are defined in the class scope of the model that you're interested in validating.
@@ -403,7 +387,7 @@ module ActiveRecord
# method, proc or string should return or evaluate to a true or false value.
# * <tt>unless</tt> - Specifies a method, proc or string to call to determine if the validation should
# not occur (e.g. :unless => :skip_validation, or :unless => Proc.new { |user| user.signup_step <= 2 }). The
- # method, proc or string should return or evaluate to a true or false value.
+ # method, proc or string should return or evaluate to a true or false value.
def validates_confirmation_of(*attr_names)
configuration = { :message => ActiveRecord::Errors.default_error_messages[:confirmation], :on => :save }
configuration.update(attr_names.extract_options!)
@@ -437,7 +421,7 @@ module ActiveRecord
# method, proc or string should return or evaluate to a true or false value.
# * <tt>unless</tt> - Specifies a method, proc or string to call to determine if the validation should
# not occur (e.g. :unless => :skip_validation, or :unless => Proc.new { |user| user.signup_step <= 2 }). The
- # method, proc or string should return or evaluate to a true or false value.
+ # method, proc or string should return or evaluate to a true or false value.
def validates_acceptance_of(*attr_names)
configuration = { :message => ActiveRecord::Errors.default_error_messages[:accepted], :on => :save, :allow_nil => true, :accept => "1" }
configuration.update(attr_names.extract_options!)
@@ -519,7 +503,7 @@ module ActiveRecord
# method, proc or string should return or evaluate to a true or false value.
# * <tt>unless</tt> - Specifies a method, proc or string to call to determine if the validation should
# not occur (e.g. :unless => :skip_validation, or :unless => Proc.new { |user| user.signup_step <= 2 }). The
- # method, proc or string should return or evaluate to a true or false value.
+ # method, proc or string should return or evaluate to a true or false value.
def validates_length_of(*attrs)
# Merge given options with defaults.
options = {
@@ -596,7 +580,7 @@ module ActiveRecord
# attribute (that maps to a column). When the record is updated, the same check is made but disregarding the record itself.
#
# Because this check is performed outside the database there is still a chance that duplicate values
- # will be inserted in two parallel transactions. To guarantee against this you should create a
+ # will be inserted in two parallel transactions. To guarantee against this you should create a
# unique index on the field. See +add_index+ for more information.
#
# Configuration options: