Created
January 7, 2011 09:53
-
-
Save bernerdschaefer/769298 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DataMapper | |
module Validations | |
module AutoValidations | |
# HACK: this method is copied directly from dm-validations, save for a | |
# single line addition to pass along allow_blank from the property to the | |
# validator. | |
def auto_generate_validations(property) | |
return if disabled_auto_validations? || skip_auto_validation_for?(property) | |
# all auto-validations (aside from presence) should skip | |
# validation when the value is nil | |
opts = { :allow_nil => true } | |
opts[:allow_blank] = property.allow_blank? # <- this is the hack! | |
if property.options.key?(:validates) | |
opts[:context] = property.options[:validates] | |
end | |
infer_presence_validation_for(property, opts.dup) | |
infer_length_validation_for(property, opts.dup) | |
infer_format_validation_for(property, opts.dup) | |
infer_uniqueness_validation_for(property, opts.dup) | |
infer_within_validation_for(property, opts.dup) | |
infer_type_validation_for(property, opts.dup) | |
end # auto_generate_validations | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment