aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-03-20 19:12:18 +0000
committerPratik Naik <pratiknaik@gmail.com>2009-03-20 19:12:18 +0000
commitcc5e019f6bc48663fe75a00e68293c0645998d14 (patch)
treed30185dd19c1452f80df178490f1667e5a6ec936 /activerecord
parent09afbfd47f8180bb6d5f907abdeab6badeda879e (diff)
downloadrails-cc5e019f6bc48663fe75a00e68293c0645998d14.tar.gz
rails-cc5e019f6bc48663fe75a00e68293c0645998d14.tar.bz2
rails-cc5e019f6bc48663fe75a00e68293c0645998d14.zip
Include ActiveModel::Validations from ActiveRecord::Validations
Diffstat (limited to 'activerecord')
-rwxr-xr-xactiverecord/lib/active_record/base.rb2
-rw-r--r--activerecord/lib/active_record/validations.rb49
2 files changed, 30 insertions, 21 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index bf7fd904b1..2a5385119d 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -3136,7 +3136,7 @@ module ActiveRecord #:nodoc:
Base.class_eval do
extend QueryCache::ClassMethods
- include ::ActiveModel::Validations, Validations
+ include Validations
include Locking::Optimistic, Locking::Pessimistic
include AttributeMethods
include Dirty
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb
index c6a950d093..c2e0c4a9ae 100644
--- a/activerecord/lib/active_record/validations.rb
+++ b/activerecord/lib/active_record/validations.rb
@@ -14,10 +14,16 @@ module ActiveRecord
end
end
+ class Errors < ActiveModel::Errors
+ end
+
module Validations
def self.included(base) # :nodoc:
base.extend ClassMethods
+ base.send :include, ActiveModel::Validations
+ base.send :include, InstanceMethods
+
base.class_eval do
alias_method_chain :save, :validation
alias_method_chain :save!, :validation
@@ -38,31 +44,34 @@ module ActiveRecord
end
end
end
-
- # The validation process on save can be skipped by passing false. The regular Base#save method is
- # replaced with this when the validations module is mixed in, which it is by default.
- def save_with_validation(perform_validation = true)
- if perform_validation && valid? || !perform_validation
- save_without_validation
- else
- false
+
+ module InstanceMethods
+ # The validation process on save can be skipped by passing false. The regular Base#save method is
+ # replaced with this when the validations module is mixed in, which it is by default.
+ def save_with_validation(perform_validation = true)
+ if perform_validation && valid? || !perform_validation
+ save_without_validation
+ else
+ false
+ end
+ end
+
+ # Attempts to save the record just like Base#save but will raise a RecordInvalid exception instead of returning false
+ # if the record is not valid.
+ def save_with_validation!
+ if valid?
+ save_without_validation!
+ else
+ raise RecordInvalid.new(self)
+ end
end
- end
- # Attempts to save the record just like Base#save but will raise a RecordInvalid exception instead of returning false
- # if the record is not valid.
- def save_with_validation!
- if valid?
- save_without_validation!
- else
- raise RecordInvalid.new(self)
+ # Returns the Errors object that holds all information about attribute error messages.
+ def errors
+ @errors ||= Errors.new(self)
end
end
- # Returns the Errors object that holds all information about attribute error messages.
- def errors
- @errors ||= Errors.new(self)
- end
end
end