From 95e14d1523ae075a39ce6c6efe68b13db43a16d8 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Wed, 16 May 2012 01:23:46 -0500 Subject: better format and fixes to validators docs --- activemodel/lib/active_model/validations/length.rb | 44 +++++++++++++--------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'activemodel/lib/active_model/validations/length.rb') diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb index 037f8c2db8..4a9a6ea7a5 100644 --- a/activemodel/lib/active_model/validations/length.rb +++ b/activemodel/lib/active_model/validations/length.rb @@ -1,5 +1,4 @@ module ActiveModel - # == Active Model Length Validator module Validations class LengthValidator < EachValidator @@ -72,35 +71,46 @@ module ActiveModel # validates_length_of :user_name, :within => 6..20, :too_long => "pick a shorter name", :too_short => "pick a longer name" # validates_length_of :zip_code, :minimum => 5, :too_short => "please enter at least 5 characters" # validates_length_of :smurf_leader, :is => 4, :message => "papa is spelled with 4 characters... don't play me." - # validates_length_of :essay, :minimum => 100, :too_short => "Your essay must be at least 100 words.", :tokenizer => lambda { |str| str.scan(/\w+/) } + # validates_length_of :essay, :minimum => 100, :too_short => "Your essay must be at least 100 words.", + # :tokenizer => lambda { |str| str.scan(/\w+/) } # end # # Configuration options: # * :minimum - The minimum size of the attribute. # * :maximum - The maximum size of the attribute. # * :is - The exact size of the attribute. - # * :within - A range specifying the minimum and maximum size of the attribute. + # * :within - A range specifying the minimum and maximum size of the + # attribute. # * :in - A synonym(or alias) for :within. # * :allow_nil - Attribute may be +nil+; skip validation. # * :allow_blank - Attribute may be blank; skip validation. - # * :too_long - The error message if the attribute goes over the maximum (default is: "is too long (maximum is %{count} characters)"). - # * :too_short - The error message if the attribute goes under the minimum (default is: "is too short (min is %{count} characters)"). - # * :wrong_length - The error message if using the :is method and the attribute is the wrong size (default is: "is the wrong length (should be %{count} characters)"). - # * :message - The error message to use for a :minimum, :maximum, or :is violation. An alias of the appropriate too_long/too_short/wrong_length message. + # * :too_long - The error message if the attribute goes over the + # maximum (default is: "is too long (maximum is %{count} characters)"). + # * :too_short - The error message if the attribute goes under the + # minimum (default is: "is too short (min is %{count} characters)"). + # * :wrong_length - The error message if using the :is method + # and the attribute is the wrong size (default is: "is the wrong length + # (should be %{count} characters)"). + # * :message - The error message to use for a :minimum, + # :maximum, or :is violation. An alias of the appropriate + # too_long/too_short/wrong_length message. # * :on - Specifies when this validation is active. Runs in all # validation contexts by default (+nil+), other options are :create # and :update. - # * :if - Specifies a method, proc or string to call to determine if the validation should - # occur (e.g. :if => :allow_validation, or :if => Proc.new { |user| user.signup_step > 2 }). The - # method, proc or string should return or evaluate to a true or false value. - # * :unless - Specifies a method, proc or string to call to determine if the validation should - # not occur (e.g. :unless => :skip_validation, or :unless => Proc.new { |user| user.signup_step <= 2 }). The - # method, proc or string should return or evaluate to a true or false value. - # * :tokenizer - Specifies how to split up the attribute string. (e.g. :tokenizer => lambda {|str| str.scan(/\w+/)} to - # count words as in above example.) - # Defaults to lambda{ |value| value.split(//) } which counts individual characters. + # * :if - Specifies a method, proc or string to call to determine if + # the validation should occur (e.g. :if => :allow_validation, or + # :if => Proc.new { |user| user.signup_step > 2 }). The method, proc + # or string should return or evaluate to a true or false value. + # * :unless - Specifies a method, proc or string to call to determine + # if the validation should not occur (e.g. :unless => :skip_validation, + # or :unless => Proc.new { |user| user.signup_step <= 2 }). The method, + # proc or string should return or evaluate to a true or false value. + # * :tokenizer - Specifies how to split up the attribute string. + # (e.g. :tokenizer => lambda {|str| str.scan(/\w+/)} to count words + # as in above example). Defaults to lambda{ |value| value.split(//) } + # which counts individual characters. # * :strict - Specifies whether validation should be strict. - # See ActiveModel::Validation#validates! for more information + # See ActiveModel::Validation#validates! for more information. def validates_length_of(*attr_names) validates_with LengthValidator, _merge_attributes(attr_names) end -- cgit v1.2.3 From 3004bc24706ed62ea7e4e752adc287dc92d168f5 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Wed, 16 May 2012 10:01:43 -0500 Subject: fixing removed empty lines and examples --- activemodel/lib/active_model/validations/length.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activemodel/lib/active_model/validations/length.rb') diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb index 4a9a6ea7a5..64b4fe2d74 100644 --- a/activemodel/lib/active_model/validations/length.rb +++ b/activemodel/lib/active_model/validations/length.rb @@ -1,4 +1,5 @@ module ActiveModel + # == Active Model Length Validator module Validations class LengthValidator < EachValidator -- cgit v1.2.3