aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2008-03-31 23:45:48 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2008-03-31 23:45:48 +0000
commita5445fd9c50161b8ccf2b36fcd26025882f73eaa (patch)
treea2a146f6b3231f5915a237aa2c837b80b7c96572
parent9ddc6143e06cdb3c86d0c954a4fed523e171886c (diff)
downloadrails-a5445fd9c50161b8ccf2b36fcd26025882f73eaa.tar.gz
rails-a5445fd9c50161b8ccf2b36fcd26025882f73eaa.tar.bz2
rails-a5445fd9c50161b8ccf2b36fcd26025882f73eaa.zip
Deprecate some more legacy
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9172 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activemodel/lib/active_model/validations.rb64
1 files changed, 19 insertions, 45 deletions
diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb
index 72eb668976..29ba60758a 100644
--- a/activemodel/lib/active_model/validations.rb
+++ b/activemodel/lib/active_model/validations.rb
@@ -622,47 +622,34 @@ module ActiveModel
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
- 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
-
- # Updates a single attribute and saves the record without going through the normal validation procedure.
- # This is especially useful for boolean flags on existing records. The regular +update_attribute+ method
- # in Base is replaced with this when the validations module is mixed in, which it is by default.
- def update_attribute_with_validation_skipping(name, value)
- send(name.to_s + '=', value)
- save(false)
- end
# Runs validate and validate_on_create or validate_on_update and returns true if no errors were added otherwise false.
def valid?
errors.clear
run_callbacks(:validate)
- validate
+
+ if responds_to?(:validate)
+ ActiveSupport::Deprecations.warn "Base#validate has been deprecated, please use Base.validate :method instead"
+ validate
+ end
if new_record?
run_callbacks(:validate_on_create)
- validate_on_create
+
+ if responds_to?(:validate_on_create)
+ ActiveSupport::Deprecations.warn(
+ "Base#validate_on_create has been deprecated, please use Base.validate :method, :on => :create instead")
+ validate_on_create
+ end
else
run_callbacks(:validate_on_update)
- validate_on_update
+
+ if responds_to?(:validate_on_update)
+ ActiveSupport::Deprecations.warn(
+ "Base#validate_on_update has been deprecated, please use Base.validate :method, :on => :update instead")
+ validate_on_update
+ end
end
errors.empty?
@@ -670,20 +657,7 @@ module ActiveModel
# Returns the Errors object that holds all information about attribute error messages.
def errors
- @errors ||= Errors.new(self)
+ @errors ||= Errors.new
end
-
- protected
- # Overwrite this method for validation checks on all saves and use Errors.add(field, msg) for invalid attributes.
- def validate #:doc:
- end
-
- # Overwrite this method for validation checks used only on creation.
- def validate_on_create #:doc:
- end
-
- # Overwrite this method for validation checks used only on updates.
- def validate_on_update # :doc:
- end
end
-end
+end \ No newline at end of file