aboutsummaryrefslogtreecommitdiff
path: root/lib/dm-validations-with-empty-errors-hack.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dm-validations-with-empty-errors-hack.rb')
-rw-r--r--lib/dm-validations-with-empty-errors-hack.rb22
1 files changed, 6 insertions, 16 deletions
diff --git a/lib/dm-validations-with-empty-errors-hack.rb b/lib/dm-validations-with-empty-errors-hack.rb
index 3916451..827f1d0 100644
--- a/lib/dm-validations-with-empty-errors-hack.rb
+++ b/lib/dm-validations-with-empty-errors-hack.rb
@@ -3,23 +3,14 @@ require 'dm-validations'
module DataMapper
module Validations
#
- # Rewrite save method to save without validations, if the validations failed, but give no reason.
+ # This only performs validations if the object being saved is dirty.
#
- # @api private
def save_self(*)
- if Validations::Context.any? && !valid?(model.validators.current_context)
- #
- # Don't do anything unusual if there is no logger available.
- #
- return false unless self.respond_to?("logger")
-
- if self.errors.empty?
- logger.warn "Forced to save #{self.inspect} without validations due to #{self.errors.inspect}."
- super
- else
- logger.warn "Failed to save #{self.inspect} with validations due to #{self.errors.inspect}."
- false
- end
+ #
+ # short-circuit if the resource is not dirty
+ #
+ if dirty_self? && Validations::Context.any? && !valid?(model.validators.current_context)
+ false
else
super
end
@@ -28,4 +19,3 @@ module DataMapper
end
-