aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/validations
diff options
context:
space:
mode:
authorObie Fernandez <obie@hashrocket.com>2010-09-20 21:35:41 -0400
committerJosé Valim <jose.valim@gmail.com>2010-09-24 12:49:16 +0200
commit275f922a23b780600a32f70de5b661371c8ffdf4 (patch)
treea49898a3284e4508768eefa9567e0cf105786f7a /activemodel/lib/active_model/validations
parent097240f60215b866d24aebd02cc4159bdc6e7451 (diff)
downloadrails-275f922a23b780600a32f70de5b661371c8ffdf4.tar.gz
rails-275f922a23b780600a32f70de5b661371c8ffdf4.tar.bz2
rails-275f922a23b780600a32f70de5b661371c8ffdf4.zip
Better shortcut options for custom validators [#5672 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activemodel/lib/active_model/validations')
-rw-r--r--activemodel/lib/active_model/validations/validates.rb15
1 files changed, 10 insertions, 5 deletions
diff --git a/activemodel/lib/active_model/validations/validates.rb b/activemodel/lib/active_model/validations/validates.rb
index f6349d57a5..77c5073c6e 100644
--- a/activemodel/lib/active_model/validations/validates.rb
+++ b/activemodel/lib/active_model/validations/validates.rb
@@ -55,14 +55,19 @@ module ActiveModel
# validates :name, :title => true
# end
#
- # The validators hash can also handle regular expressions, ranges and arrays:
+ # The validators hash can also handle regular expressions, ranges,
+ # arrays and strings in shortcut form, e.g.
#
# validates :email, :format => /@/
# validates :gender, :inclusion => %w(male female)
# validates :password, :length => 6..20
#
- # Finally, the options :if, :unless, :on, :allow_blank and :allow_nil can be given
- # to one specific validator:
+ # When using shortcut form, ranges and arrays are passed to your
+ # validator's initializer as +options[:in]+ while other types including
+ # regular expressions and strings are passed as +options[:with]+
+ #
+ # Finally, the options +:if+, +:unless+, +:on+, +:allow_blank+ and +:allow_nil+ can be given
+ # to one specific validator, as a hash:
#
# validates :password, :presence => { :if => :password_required? }, :confirmation => true
#
@@ -99,10 +104,10 @@ module ActiveModel
{}
when Hash
options
- when Regexp
- { :with => options }
when Range, Array
{ :in => options }
+ else
+ { :with => options }
end
end
end