Skip to content
This repository
Browse code

copy-edits 8d96b89

  • Loading branch information...
commit 0d41fa956252a6864455ebc64c037da076355fa1 1 parent 5e69deb
Xavier Noria authored February 21, 2011 bowsersenior committed February 21, 2011
4  activemodel/lib/active_model/validations.rb
@@ -71,8 +71,8 @@ module ClassMethods
71 71
       #   end
72 72
       #
73 73
       # Options:
74  
-      # * <tt>:on</tt> - Specifies the context where this validation is active 
75  
-      #   (e.g. <tt>:on => :create</tt> or <tt>:on => :special_rules</tt>)
  74
+      # * <tt>:on</tt> - Specifies the context where this validation is active
  75
+      #   (e.g. <tt>:on => :create</tt> or <tt>:on => :custom_validation_context</tt>)
76 76
       # * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+.
77 77
       # * <tt>:allow_blank</tt> - Skip validation if attribute is blank.
78 78
       # * <tt>:if</tt> - Specifies a method, proc or string to call to determine
6  activemodel/lib/active_model/validations/acceptance.rb
@@ -37,9 +37,9 @@ module HelperMethods
37 37
       # Configuration options:
38 38
       # * <tt>:message</tt> - A custom error message (default is: "must be
39 39
       #   accepted").
40  
-      # * <tt>:on</tt> - Specifies when this validation is active (default is
41  
-      #   <tt>nil</tt>, other options are <tt>:create</tt> and
42  
-      #   <tt>:update</tt>).
  40
+      # * <tt>:on</tt> - Specifies when this validation is active. Runs in all
  41
+      #   validation contexts by default (+nil+), other options are <tt>:create</tt>
  42
+      #   and <tt>:update</tt>.
43 43
       # * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+ (default
44 44
       #   is true).
45 45
       # * <tt>:accept</tt> - Specifies value that is considered accepted.
5  activemodel/lib/active_model/validations/confirmation.rb
@@ -45,8 +45,9 @@ module HelperMethods
45 45
       # Configuration options:
46 46
       # * <tt>:message</tt> - A custom error message (default is: "doesn't match
47 47
       #   confirmation").
48  
-      # * <tt>:on</tt> - Specifies when this validation is active (default is
49  
-      #   <tt>:nil</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
  48
+      # * <tt>:on</tt> - Specifies when this validation is active. Runs in all
  49
+      #   validation contexts by default (+nil+), other options are <tt>:create</tt>
  50
+      #   and <tt>:update</tt>.
50 51
       # * <tt>:if</tt> - Specifies a method, proc or string to call to determine
51 52
       #   if the validation should occur (e.g. <tt>:if => :allow_validation</tt>,
52 53
       #   or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>).  The
3  activemodel/lib/active_model/validations/exclusion.rb
@@ -29,6 +29,9 @@ module HelperMethods
29 29
       # * <tt>:message</tt> - Specifies a custom error message (default is: "is reserved").
30 30
       # * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute is +nil+ (default is +false+).
31 31
       # * <tt>:allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is +false+).
  32
+      # * <tt>:on</tt> - Specifies when this validation is active. Runs in all
  33
+      #   validation contexts by default (+nil+), other options are <tt>:create</tt>
  34
+      #   and <tt>:update</tt>.
32 35
       # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
33 36
       #   occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>).  The
34 37
       #   method, proc or string should return or evaluate to a true or false value.
4  activemodel/lib/active_model/validations/format.rb
@@ -51,7 +51,9 @@ module HelperMethods
51 51
       # * <tt>:allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is +false+).
52 52
       # * <tt>:with</tt> - Regular expression that if the attribute matches will result in a successful validation.
53 53
       # * <tt>:without</tt> - Regular expression that if the attribute does not match will result in a successful validation.
54  
-      # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>nil</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
  54
+      # * <tt>:on</tt> - Specifies when this validation is active. Runs in all
  55
+      #   validation contexts by default (+nil+), other options are <tt>:create</tt>
  56
+      #   and <tt>:update</tt>.
55 57
       # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
56 58
       #   occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>).  The
57 59
       #   method, proc or string should return or evaluate to a true or false value.
3  activemodel/lib/active_model/validations/inclusion.rb
@@ -38,6 +38,9 @@ module HelperMethods
38 38
       # * <tt>:message</tt> - Specifies a custom error message (default is: "is not included in the list").
39 39
       # * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute is +nil+ (default is +false+).
40 40
       # * <tt>:allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is +false+).
  41
+      # * <tt>:on</tt> - Specifies when this validation is active. Runs in all
  42
+      #   validation contexts by default (+nil+), other options are <tt>:create</tt>
  43
+      #   and <tt>:update</tt>.
41 44
       # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
42 45
       #   occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>).  The
43 46
       #   method, proc or string should return or evaluate to a true or false value.
4  activemodel/lib/active_model/validations/length.rb
@@ -83,7 +83,9 @@ module HelperMethods
83 83
       # * <tt>:too_short</tt> - The error message if the attribute goes under the minimum (default is: "is too short (min is %{count} characters)").
84 84
       # * <tt>:wrong_length</tt> - The error message if using the <tt>:is</tt> method and the attribute is the wrong size (default is: "is the wrong length (should be %{count} characters)").
85 85
       # * <tt>:message</tt> - The error message to use for a <tt>:minimum</tt>, <tt>:maximum</tt>, or <tt>:is</tt> violation.  An alias of the appropriate <tt>too_long</tt>/<tt>too_short</tt>/<tt>wrong_length</tt> message.
86  
-      # * <tt>:on</tt> - Specifies the context where this validation is active (e.g. <tt>:on => :create</tt> or <tt>:on => :special_rules</tt>)
  86
+      # * <tt>:on</tt> - Specifies when this validation is active. Runs in all
  87
+      #   validation contexts by default (+nil+), other options are <tt>:create</tt>
  88
+      #   and <tt>:update</tt>.
87 89
       # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
88 90
       #   occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>).  The
89 91
       #   method, proc or string should return or evaluate to a true or false value.
4  activemodel/lib/active_model/validations/numericality.rb
@@ -93,7 +93,9 @@ module HelperMethods
93 93
       #
94 94
       # Configuration options:
95 95
       # * <tt>:message</tt> - A custom error message (default is: "is not a number").
96  
-      # * <tt>:on</tt> - Specifies the context where this validation is active (e.g. <tt>:on => :create</tt> or <tt>:on => :special_rules</tt>)
  96
+      # * <tt>:on</tt> - Specifies when this validation is active. Runs in all
  97
+      #   validation contexts by default (+nil+), other options are <tt>:create</tt>
  98
+      #   and <tt>:update</tt>.
97 99
       # * <tt>:only_integer</tt> - Specifies whether the value has to be an integer, e.g. an integral value (default is +false+).
98 100
       # * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+ (default is +false+). Notice that for fixnum and float columns empty strings are converted to +nil+.
99 101
       # * <tt>:greater_than</tt> - Specifies the value must be greater than the supplied value.
4  activemodel/lib/active_model/validations/presence.rb
@@ -26,7 +26,9 @@ module HelperMethods
26 26
       #
27 27
       # Configuration options:
28 28
       # * <tt>message</tt> - A custom error message (default is: "can't be blank").
29  
-      # * <tt>:on</tt> - Specifies the context where this validation is active (e.g. <tt>:on => :create</tt> or <tt>:on => :special_rules</tt>)
  29
+      # * <tt>:on</tt> - Specifies when this validation is active. Runs in all
  30
+      #   validation contexts by default (+nil+), other options are <tt>:create</tt>
  31
+      #   and <tt>:update</tt>.
30 32
       # * <tt>if</tt> - Specifies a method, proc or string to call to determine if the validation should
31 33
       #   occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>).
32 34
       #   The method, proc or string should return or evaluate to a true or false value.
14  activerecord/lib/active_record/validations.rb
@@ -20,7 +20,7 @@ def initialize(record)
20 20
 
21 21
   # = Active Record Validations
22 22
   #
23  
-  # Active Record includes the majority of its validations from ActiveModel::Validations
  23
+  # Active Record includes the majority of its validations from <tt>ActiveModel::Validations</tt>
24 24
   # all of which accept the <tt>:on</tt> argument to define the context where the
25 25
   # validations are active. Active Record will always supply either the context of
26 26
   # <tt>:create</tt> or <tt>:update</tt> dependent on whether the model is a
@@ -56,14 +56,14 @@ def save!(options={})
56 56
       perform_validations(options) ? super : raise(RecordInvalid.new(self))
57 57
     end
58 58
 
59  
-    # Runs all the specified validations and returns true if no errors were added otherwise false.
  59
+    # Runs all the validations within the specified context. Returns true if no errors are found,
  60
+    # false otherwise.
60 61
     #
61  
-    # ==== Arguments
  62
+    # If the argument is false (default is +nil+), the context is set to <tt>:create</tt> if
  63
+    # <tt>new_record?</tt> is true, and to <tt>:update</tt> if it is not.
62 64
     #
63  
-    # * <tt>context</tt> - Context to scope the execution of the validations. Default is <tt>nil</tt>.
64  
-    #   If <tt>nil</tt> then the response of <tt>new_record?</tt> will determine the context. If <tt>new_record?</tt>
65  
-    #   returns true the context will be <tt>:create</tt>, otherwise <tt>:update</tt>.  Validation contexts
66  
-    #   for each validation can be defined using the <tt>:on</tt> option
  65
+    # Validations with no <tt>:on</tt> option will run no matter the context. Validations with
  66
+    # some <tt>:on</tt> option will only run in the specified context.
67 67
     def valid?(context = nil)
68 68
       context ||= (new_record? ? :create : :update)
69 69
       output = super(context)
4  activerecord/lib/active_record/validations/associated.rb
@@ -33,7 +33,9 @@ module ClassMethods
33 33
       #
34 34
       # Configuration options:
35 35
       # * <tt>:message</tt> - A custom error message (default is: "is invalid")
36  
-      # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>nil</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
  36
+      # * <tt>:on</tt> - Specifies when this validation is active. Runs in all
  37
+      #   validation contexts by default (+nil+), other options are <tt>:create</tt>
  38
+      #   and <tt>:update</tt>.
37 39
       # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
38 40
       #   occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>).  The
39 41
       #   method, proc or string should return or evaluate to a true or false value.

0 notes on commit 0d41fa9

Please sign in to comment.
Something went wrong with that request. Please try again.