
[PATCH] allow nil values for within validator
Reported by Roman | December 19th, 2008 @ 09:46 AM
Similary to numeric_validator added option :allow_nil to within_validator:
diff --git a/dm-validations/lib/dm-validations/within_validator.rb b/dm-validations/li
index 583363e..018440b 100644
--- a/dm-validations/lib/dm-validations/within_validator.rb
+++ b/dm-validations/lib/dm-validations/within_validator.rb
@@ -14,8 +14,11 @@ module DataMapper
end
def call(target)
- includes = @options[:set].include?(target.send(field_name))
- return true if includes
+ value = target.send(field_name)
+ return true if @options[:allow_nil] && value.nil?
+
+ includes = @options[:set].include?(value)
+ return true if includes || target.send(field_name).nil?
field_name = Extlib::Inflection.humanize(@field_name)
if @options[:set].is_a?(Range)
Comments and changes to this ticket
-
Dan Kubb (dkubb) January 8th, 2009 @ 02:44 PM
- Assigned user set to Michael Klishin (antares)
-
Michael Klishin (antares) January 10th, 2009 @ 04:32 AM
- State changed from unconfirmed to accepted
-
Michael Klishin (antares) January 10th, 2009 @ 06:11 AM
- State changed from accepted to resolved
Has already been applied, I just improved spec example a bit.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »