activemodel 3.2.3 → 3.2.4.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- ## Rails 3.2.3 (unreleased) ##
1
+ ## Rails 3.2.3 (March 30, 2012) ##
2
2
 
3
3
  * No changes.
4
4
 
@@ -50,7 +50,7 @@ modules:
50
50
  This generates +before_create+, +around_create+ and +after_create+
51
51
  class methods that wrap your create method.
52
52
 
53
- {Learn more}[link:classes/ActiveModel/CallBacks.html]
53
+ {Learn more}[link:classes/ActiveModel/Callbacks.html]
54
54
 
55
55
  * Tracking value changes
56
56
 
@@ -192,7 +192,7 @@ The latest version of Active Model can be installed with RubyGems:
192
192
 
193
193
  Source code can be downloaded as part of the Rails project on GitHub
194
194
 
195
- * https://github.com/rails/rails/tree/master/activemodel
195
+ * https://github.com/rails/rails/tree/3-2-stable/activemodel
196
196
 
197
197
 
198
198
  == License
@@ -165,6 +165,20 @@ module ActiveModel
165
165
  end
166
166
  end
167
167
 
168
+ # Clean the +Errors+ object if instance is duped
169
+ def initialize_dup(other) # :nodoc:
170
+ @errors = nil
171
+ end
172
+
173
+ # Backport dup from 1.9 so that #initialize_dup gets called
174
+ unless Object.respond_to?(:initialize_dup)
175
+ def dup # :nodoc:
176
+ copy = super
177
+ copy.initialize_dup(self)
178
+ copy
179
+ end
180
+ end
181
+
168
182
  # Returns the +Errors+ object that holds all information about attribute error messages.
169
183
  def errors
170
184
  @errors ||= Errors.new(self)
@@ -1,5 +1,4 @@
1
1
  module ActiveModel
2
-
3
2
  # == Active Model Acceptance Validator
4
3
  module Validations
5
4
  class AcceptanceValidator < EachValidator
@@ -59,7 +58,7 @@ module ActiveModel
59
58
  # The method, proc or string should return or evaluate to a true or
60
59
  # false value.
61
60
  # * <tt>:strict</tt> - Specifies whether validation should be strict.
62
- # See <tt>ActiveModel::Validation#validates!</tt> for more information
61
+ # See <tt>ActiveModel::Validation#validates!</tt> for more information.
63
62
  def validates_acceptance_of(*attr_names)
64
63
  validates_with AcceptanceValidator, _merge_attributes(attr_names)
65
64
  end
@@ -1,5 +1,4 @@
1
1
  module ActiveModel
2
-
3
2
  # == Active Model Confirmation Validator
4
3
  module Validations
5
4
  class ConfirmationValidator < EachValidator
@@ -59,7 +58,7 @@ module ActiveModel
59
58
  # <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
60
59
  # method, proc or string should return or evaluate to a true or false value.
61
60
  # * <tt>:strict</tt> - Specifies whether validation should be strict.
62
- # See <tt>ActiveModel::Validation#validates!</tt> for more information
61
+ # See <tt>ActiveModel::Validation#validates!</tt> for more information.
63
62
  def validates_confirmation_of(*attr_names)
64
63
  validates_with ConfirmationValidator, _merge_attributes(attr_names)
65
64
  end
@@ -1,7 +1,6 @@
1
1
  require 'active_support/core_ext/range'
2
2
 
3
3
  module ActiveModel
4
-
5
4
  # == Active Model Exclusion Validator
6
5
  module Validations
7
6
  class ExclusionValidator < EachValidator
@@ -24,43 +23,50 @@ module ActiveModel
24
23
 
25
24
  private
26
25
 
27
- # In Ruby 1.9 <tt>Range#include?</tt> on non-numeric ranges checks all possible values in the
28
- # range for equality, so it may be slow for large ranges. The new <tt>Range#cover?</tt>
29
- # uses the previous logic of comparing a value with the range endpoints.
26
+ # In Ruby 1.9 <tt>Range#include?</tt> on non-numeric ranges checks all possible
27
+ # values in the range for equality, so it may be slow for large ranges. The new
28
+ # <tt>Range#cover?</tt> uses the previous logic of comparing a value with the
29
+ # range endpoints.
30
30
  def inclusion_method(enumerable)
31
31
  enumerable.is_a?(Range) ? :cover? : :include?
32
32
  end
33
33
  end
34
34
 
35
35
  module HelperMethods
36
- # Validates that the value of the specified attribute is not in a particular enumerable object.
36
+ # Validates that the value of the specified attribute is not in a particular
37
+ # enumerable object.
37
38
  #
38
39
  # class Person < ActiveRecord::Base
39
40
  # validates_exclusion_of :username, :in => %w( admin superuser ), :message => "You don't belong here"
40
41
  # validates_exclusion_of :age, :in => 30..60, :message => "This site is only for under 30 and over 60"
41
42
  # validates_exclusion_of :format, :in => %w( mov avi ), :message => "extension %{value} is not allowed"
42
- # validates_exclusion_of :password, :in => lambda { |p| [p.username, p.first_name] }, :message => "should not be the same as your username or first name"
43
+ # validates_exclusion_of :password, :in => lambda { |p| [p.username, p.first_name] },
44
+ # :message => "should not be the same as your username or first name"
43
45
  # end
44
46
  #
45
47
  # Configuration options:
46
- # * <tt>:in</tt> - An enumerable object of items that the value shouldn't be part of.
47
- # This can be supplied as a proc or lambda which returns an enumerable. If the enumerable
48
- # is a range the test is performed with <tt>Range#cover?</tt>
48
+ # * <tt>:in</tt> - An enumerable object of items that the value shouldn't be
49
+ # part of. This can be supplied as a proc or lambda which returns an enumerable.
50
+ # If the enumerable is a range the test is performed with <tt>Range#cover?</tt>
49
51
  # (backported in Active Support for 1.8), otherwise with <tt>include?</tt>.
50
52
  # * <tt>:message</tt> - Specifies a custom error message (default is: "is reserved").
51
- # * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute is +nil+ (default is +false+).
52
- # * <tt>:allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is +false+).
53
+ # * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute
54
+ # is +nil+ (default is +false+).
55
+ # * <tt>:allow_blank</tt> - If set to true, skips this validation if the
56
+ # attribute is blank (default is +false+).
53
57
  # * <tt>:on</tt> - Specifies when this validation is active. Runs in all
54
58
  # validation contexts by default (+nil+), other options are <tt>:create</tt>
55
59
  # and <tt>:update</tt>.
56
- # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
57
- # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
58
- # method, proc or string should return or evaluate to a true or false value.
59
- # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
60
- # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
61
- # method, proc or string should return or evaluate to a true or false value.
60
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the
61
+ # validation should occur (e.g. <tt>:if => :allow_validation</tt>, or
62
+ # <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The method, proc
63
+ # or string should return or evaluate to a true or false value.
64
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if
65
+ # the validation should not occur (e.g. <tt>:unless => :skip_validation</tt>,
66
+ # or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The method,
67
+ # proc or string should return or evaluate to a true or false value.
62
68
  # * <tt>:strict</tt> - Specifies whether validation should be strict.
63
- # See <tt>ActiveModel::Validation#validates!</tt> for more information
69
+ # See <tt>ActiveModel::Validation#validates!</tt> for more information.
64
70
  def validates_exclusion_of(*attr_names)
65
71
  validates_with ExclusionValidator, _merge_attributes(attr_names)
66
72
  end
@@ -1,5 +1,4 @@
1
1
  module ActiveModel
2
-
3
2
  # == Active Model Format Validator
4
3
  module Validations
5
4
  class FormatValidator < EachValidator
@@ -42,50 +41,62 @@ module ActiveModel
42
41
  end
43
42
 
44
43
  module HelperMethods
45
- # Validates whether the value of the specified attribute is of the correct form, going by the regular expression provided.
46
- # You can require that the attribute matches the regular expression:
44
+ # Validates whether the value of the specified attribute is of the correct form,
45
+ # going by the regular expression provided. You can require that the attribute
46
+ # matches the regular expression:
47
47
  #
48
48
  # class Person < ActiveRecord::Base
49
49
  # validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create
50
50
  # end
51
51
  #
52
- # Alternatively, you can require that the specified attribute does _not_ match the regular expression:
52
+ # Alternatively, you can require that the specified attribute does _not_ match
53
+ # the regular expression:
53
54
  #
54
55
  # class Person < ActiveRecord::Base
55
56
  # validates_format_of :email, :without => /NOSPAM/
56
57
  # end
57
58
  #
58
- # You can also provide a proc or lambda which will determine the regular expression that will be used to validate the attribute
59
+ # You can also provide a proc or lambda which will determine the regular
60
+ # expression that will be used to validate the attribute.
59
61
  #
60
62
  # class Person < ActiveRecord::Base
61
63
  # # Admin can have number as a first letter in their screen name
62
- # validates_format_of :screen_name, :with => lambda{ |person| person.admin? ? /\A[a-z0-9][a-z0-9_\-]*\Z/i : /\A[a-z][a-z0-9_\-]*\Z/i }
64
+ # validates_format_of :screen_name,
65
+ # :with => lambda{ |person| person.admin? ? /\A[a-z0-9][a-z0-9_\-]*\Z/i : /\A[a-z][a-z0-9_\-]*\Z/i }
63
66
  # end
64
67
  #
65
- # Note: use <tt>\A</tt> and <tt>\Z</tt> to match the start and end of the string, <tt>^</tt> and <tt>$</tt> match the start/end of a line.
68
+ # Note: use <tt>\A</tt> and <tt>\Z</tt> to match the start and end of the string,
69
+ # <tt>^</tt> and <tt>$</tt> match the start/end of a line.
66
70
  #
67
- # You must pass either <tt>:with</tt> or <tt>:without</tt> as an option. In addition, both must be a regular expression
68
- # or a proc or lambda, or else an exception will be raised.
71
+ # You must pass either <tt>:with</tt> or <tt>:without</tt> as an option. In
72
+ # addition, both must be a regular expression or a proc or lambda, or else an
73
+ # exception will be raised.
69
74
  #
70
75
  # Configuration options:
71
76
  # * <tt>:message</tt> - A custom error message (default is: "is invalid").
72
- # * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute is +nil+ (default is +false+).
73
- # * <tt>:allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is +false+).
74
- # * <tt>:with</tt> - Regular expression that if the attribute matches will result in a successful validation.
75
- # This can be provided as a proc or lambda returning regular expression which will be called at runtime.
76
- # * <tt>:without</tt> - Regular expression that if the attribute does not match will result in a successful validation.
77
- # This can be provided as a proc or lambda returning regular expression which will be called at runtime.
77
+ # * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute
78
+ # is +nil+ (default is +false+).
79
+ # * <tt>:allow_blank</tt> - If set to true, skips this validation if the
80
+ # attribute is blank (default is +false+).
81
+ # * <tt>:with</tt> - Regular expression that if the attribute matches will
82
+ # result in a successful validation. This can be provided as a proc or lambda
83
+ # returning regular expression which will be called at runtime.
84
+ # * <tt>:without</tt> - Regular expression that if the attribute does not match
85
+ # will result in a successful validation. This can be provided as a proc or
86
+ # lambda returning regular expression which will be called at runtime.
78
87
  # * <tt>:on</tt> - Specifies when this validation is active. Runs in all
79
88
  # validation contexts by default (+nil+), other options are <tt>:create</tt>
80
89
  # and <tt>:update</tt>.
81
- # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
82
- # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
83
- # method, proc or string should return or evaluate to a true or false value.
84
- # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
85
- # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
86
- # method, proc or string should return or evaluate to a true or false value.
90
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the
91
+ # validation should occur (e.g. <tt>:if => :allow_validation</tt>, or
92
+ # <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The method, proc
93
+ # or string should return or evaluate to a true or false value.
94
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if
95
+ # the validation should not occur (e.g. <tt>:unless => :skip_validation</tt>,
96
+ # or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The method,
97
+ # proc or string should return or evaluate to a true or false value.
87
98
  # * <tt>:strict</tt> - Specifies whether validation should be strict.
88
- # See <tt>ActiveModel::Validation#validates!</tt> for more information
99
+ # See <tt>ActiveModel::Validation#validates!</tt> for more information.
89
100
  def validates_format_of(*attr_names)
90
101
  validates_with FormatValidator, _merge_attributes(attr_names)
91
102
  end
@@ -1,7 +1,6 @@
1
1
  require 'active_support/core_ext/range'
2
2
 
3
3
  module ActiveModel
4
-
5
4
  # == Active Model Inclusion Validator
6
5
  module Validations
7
6
  class InclusionValidator < EachValidator
@@ -24,16 +23,18 @@ module ActiveModel
24
23
 
25
24
  private
26
25
 
27
- # In Ruby 1.9 <tt>Range#include?</tt> on non-numeric ranges checks all possible values in the
28
- # range for equality, so it may be slow for large ranges. The new <tt>Range#cover?</tt>
29
- # uses the previous logic of comparing a value with the range endpoints.
26
+ # In Ruby 1.9 <tt>Range#include?</tt> on non-numeric ranges checks all possible
27
+ # values in the range for equality, so it may be slow for large ranges. The new
28
+ # <tt>Range#cover?</tt> uses the previous logic of comparing a value with the
29
+ # range endpoints.
30
30
  def inclusion_method(enumerable)
31
31
  enumerable.is_a?(Range) ? :cover? : :include?
32
32
  end
33
33
  end
34
34
 
35
35
  module HelperMethods
36
- # Validates whether the value of the specified attribute is available in a particular enumerable object.
36
+ # Validates whether the value of the specified attribute is available in a
37
+ # particular enumerable object.
37
38
  #
38
39
  # class Person < ActiveRecord::Base
39
40
  # validates_inclusion_of :gender, :in => %w( m f )
@@ -47,20 +48,25 @@ module ActiveModel
47
48
  # supplied as a proc or lambda which returns an enumerable. If the enumerable
48
49
  # is a range the test is performed with <tt>Range#cover?</tt>
49
50
  # (backported in Active Support for 1.8), otherwise with <tt>include?</tt>.
50
- # * <tt>:message</tt> - Specifies a custom error message (default is: "is not included in the list").
51
- # * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute is +nil+ (default is +false+).
52
- # * <tt>:allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is +false+).
51
+ # * <tt>:message</tt> - Specifies a custom error message (default is: "is not
52
+ # included in the list").
53
+ # * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute
54
+ # is +nil+ (default is +false+).
55
+ # * <tt>:allow_blank</tt> - If set to true, skips this validation if the
56
+ # attribute is blank (default is +false+).
53
57
  # * <tt>:on</tt> - Specifies when this validation is active. Runs in all
54
58
  # validation contexts by default (+nil+), other options are <tt>:create</tt>
55
59
  # and <tt>:update</tt>.
56
- # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
57
- # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
58
- # method, proc or string should return or evaluate to a true or false value.
59
- # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
60
- # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
61
- # method, proc or string should return or evaluate to a true or false value.
60
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if
61
+ # the validation should occur (e.g. <tt>:if => :allow_validation</tt>, or
62
+ # <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The method, proc
63
+ # or string should return or evaluate to a true or false value.
64
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine
65
+ # if the validation should not occur (e.g. <tt>:unless => :skip_validation</tt>,
66
+ # or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The method,
67
+ # proc or string should return or evaluate to a true or false value.
62
68
  # * <tt>:strict</tt> - Specifies whether validation should be strict.
63
- # See <tt>ActiveModel::Validation#validates!</tt> for more information
69
+ # See <tt>ActiveModel::Validation#validates!</tt> for more information.
64
70
  def validates_inclusion_of(*attr_names)
65
71
  validates_with InclusionValidator, _merge_attributes(attr_names)
66
72
  end
@@ -1,7 +1,6 @@
1
1
  require "active_support/core_ext/string/encoding"
2
2
 
3
3
  module ActiveModel
4
-
5
4
  # == Active Model Length Validator
6
5
  module Validations
7
6
  class LengthValidator < EachValidator
@@ -68,8 +67,8 @@ module ActiveModel
68
67
  end
69
68
 
70
69
  module HelperMethods
71
-
72
- # Validates that the specified attribute matches the length restrictions supplied. Only one option can be used at a time:
70
+ # Validates that the specified attribute matches the length restrictions supplied.
71
+ # Only one option can be used at a time:
73
72
  #
74
73
  # class Person < ActiveRecord::Base
75
74
  # validates_length_of :first_name, :maximum => 30
@@ -79,35 +78,45 @@ module ActiveModel
79
78
  # validates_length_of :user_name, :within => 6..20, :too_long => "pick a shorter name", :too_short => "pick a longer name"
80
79
  # validates_length_of :zip_code, :minimum => 5, :too_short => "please enter at least 5 characters"
81
80
  # validates_length_of :smurf_leader, :is => 4, :message => "papa is spelled with 4 characters... don't play me."
82
- # validates_length_of :essay, :minimum => 100, :too_short => "Your essay must be at least 100 words.", :tokenizer => lambda { |str| str.scan(/\w+/) }
81
+ # validates_length_of :essay, :minimum => 100, :too_short => "Your essay must be at least 100 words.",
82
+ # :tokenizer => lambda { |str| str.scan(/\w+/) }
83
83
  # end
84
84
  #
85
85
  # Configuration options:
86
86
  # * <tt>:minimum</tt> - The minimum size of the attribute.
87
87
  # * <tt>:maximum</tt> - The maximum size of the attribute.
88
88
  # * <tt>:is</tt> - The exact size of the attribute.
89
- # * <tt>:within</tt> - A range specifying the minimum and maximum size of the attribute.
89
+ # * <tt>:within</tt> - A range specifying the minimum and maximum size of the
90
+ # attribute.
90
91
  # * <tt>:in</tt> - A synonym(or alias) for <tt>:within</tt>.
91
92
  # * <tt>:allow_nil</tt> - Attribute may be +nil+; skip validation.
92
93
  # * <tt>:allow_blank</tt> - Attribute may be blank; skip validation.
93
- # * <tt>:too_long</tt> - The error message if the attribute goes over the maximum (default is: "is too long (maximum is %{count} characters)").
94
- # * <tt>:too_short</tt> - The error message if the attribute goes under the minimum (default is: "is too short (min is %{count} characters)").
95
- # * <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)").
96
- # * <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.
94
+ # * <tt>:too_long</tt> - The error message if the attribute goes over the
95
+ # maximum (default is: "is too long (maximum is %{count} characters)").
96
+ # * <tt>:too_short</tt> - The error message if the attribute goes under the
97
+ # minimum (default is: "is too short (min is %{count} characters)").
98
+ # * <tt>:wrong_length</tt> - The error message if using the <tt>:is</tt> method
99
+ # and the attribute is the wrong size (default is: "is the wrong length
100
+ # should be %{count} characters)").
101
+ # * <tt>:message</tt> - The error message to use for a <tt>:minimum</tt>,
102
+ # <tt>:maximum</tt>, or <tt>:is</tt> violation. An alias of the appropriate
103
+ # <tt>too_long</tt>/<tt>too_short</tt>/<tt>wrong_length</tt> message.
97
104
  # * <tt>:on</tt> - Specifies when this validation is active. Runs in all
98
105
  # validation contexts by default (+nil+), other options are <tt>:create</tt>
99
106
  # and <tt>:update</tt>.
100
- # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
101
- # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
102
- # method, proc or string should return or evaluate to a true or false value.
103
- # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
104
- # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
107
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if
108
+ # the validation should occur (e.g. <tt>:if => :allow_validation</tt>, or
109
+ # <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The method, proc
110
+ # or string should return or evaluate to a true or false value.
111
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine
112
+ # if the validation should not occur (e.g. <tt>:unless => :skip_validation</tt>,
113
+ # or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
105
114
  # method, proc or string should return or evaluate to a true or false value.
106
- # * <tt>:tokenizer</tt> - Specifies how to split up the attribute string. (e.g. <tt>:tokenizer => lambda {|str| str.scan(/\w+/)}</tt> to
107
- # count words as in above example.)
108
- # Defaults to <tt>lambda{ |value| value.split(//) }</tt> which counts individual characters.
115
+ # * <tt>:tokenizer</tt> - Specifies how to split up the attribute string.
116
+ # (e.g. <tt>:tokenizer => lambda {|str| str.scan(/\w+/)}</tt> to count words
117
+ # as in above example). Defaults to <tt>lambda{ |value| value.split(//) }</tt> which counts individual characters.
109
118
  # * <tt>:strict</tt> - Specifies whether validation should be strict.
110
- # See <tt>ActiveModel::Validation#validates!</tt> for more information
119
+ # See <tt>ActiveModel::Validation#validates!</tt> for more information.
111
120
  def validates_length_of(*attr_names)
112
121
  validates_with LengthValidator, _merge_attributes(attr_names)
113
122
  end
@@ -1,5 +1,4 @@
1
1
  module ActiveModel
2
-
3
2
  # == Active Model Numericality Validator
4
3
  module Validations
5
4
  class NumericalityValidator < EachValidator
@@ -93,22 +92,30 @@ module ActiveModel
93
92
  # validation contexts by default (+nil+), other options are <tt>:create</tt>
94
93
  # and <tt>:update</tt>.
95
94
  # * <tt>:only_integer</tt> - Specifies whether the value has to be an integer, e.g. an integral value (default is +false+).
96
- # * <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+.
97
- # * <tt>:greater_than</tt> - Specifies the value must be greater than the supplied value.
98
- # * <tt>:greater_than_or_equal_to</tt> - Specifies the value must be greater than or equal the supplied value.
95
+ # * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+ (default is
96
+ # +false+). Notice that for fixnum and float columns empty strings are
97
+ # converted to +nil+.
98
+ # * <tt>:greater_than</tt> - Specifies the value must be greater than the
99
+ # supplied value.
100
+ # * <tt>:greater_than_or_equal_to</tt> - Specifies the value must be greater
101
+ # than or equal the supplied value.
99
102
  # * <tt>:equal_to</tt> - Specifies the value must be equal to the supplied value.
100
- # * <tt>:less_than</tt> - Specifies the value must be less than the supplied value.
101
- # * <tt>:less_than_or_equal_to</tt> - Specifies the value must be less than or equal the supplied value.
103
+ # * <tt>:less_than</tt> - Specifies the value must be less than the supplied
104
+ # value.
105
+ # * <tt>:less_than_or_equal_to</tt> - Specifies the value must be less than
106
+ # or equal the supplied value.
102
107
  # * <tt>:odd</tt> - Specifies the value must be an odd number.
103
108
  # * <tt>:even</tt> - Specifies the value must be an even number.
104
- # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
105
- # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
106
- # method, proc or string should return or evaluate to a true or false value.
107
- # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
108
- # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
109
- # method, proc or string should return or evaluate to a true or false value.
109
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine
110
+ # if the validation should occur (e.g. <tt>:if => :allow_validation</tt>,
111
+ # or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The method,
112
+ # proc or string should return or evaluate to a true or false value.
113
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine
114
+ # if the validation should not occur (e.g. <tt>:unless => :skip_validation</tt>,
115
+ # or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The method,
116
+ # proc or string should return or evaluate to a true or false value.
110
117
  # * <tt>:strict</tt> - Specifies whether validation should be strict.
111
- # See <tt>ActiveModel::Validation#validates!</tt> for more information
118
+ # See <tt>ActiveModel::Validation#validates!</tt> for more information.
112
119
  #
113
120
  # The following checks can also be supplied with a proc or a symbol which corresponds to a method:
114
121
  # * <tt>:greater_than</tt>
@@ -117,11 +124,12 @@ module ActiveModel
117
124
  # * <tt>:less_than</tt>
118
125
  # * <tt>:less_than_or_equal_to</tt>
119
126
  #
127
+ # For example:
128
+ #
120
129
  # class Person < ActiveRecord::Base
121
130
  # validates_numericality_of :width, :less_than => Proc.new { |person| person.height }
122
131
  # validates_numericality_of :width, :greater_than => :minimum_weight
123
132
  # end
124
- #
125
133
  def validates_numericality_of(*attr_names)
126
134
  validates_with NumericalityValidator, _merge_attributes(attr_names)
127
135
  end
@@ -1,7 +1,6 @@
1
1
  require 'active_support/core_ext/object/blank'
2
2
 
3
3
  module ActiveModel
4
-
5
4
  # == Active Model Presence Validator
6
5
  module Validations
7
6
  class PresenceValidator < EachValidator
@@ -11,7 +10,8 @@ module ActiveModel
11
10
  end
12
11
 
13
12
  module HelperMethods
14
- # Validates that the specified attributes are not blank (as defined by Object#blank?). Happens by default on save. Example:
13
+ # Validates that the specified attributes are not blank (as defined by
14
+ # Object#blank?). Happens by default on save. Example:
15
15
  #
16
16
  # class Person < ActiveRecord::Base
17
17
  # validates_presence_of :first_name
@@ -19,25 +19,28 @@ module ActiveModel
19
19
  #
20
20
  # The first_name attribute must be in the object and it cannot be blank.
21
21
  #
22
- # If you want to validate the presence of a boolean field (where the real values are true and false),
23
- # you will want to use <tt>validates_inclusion_of :field_name, :in => [true, false]</tt>.
22
+ # If you want to validate the presence of a boolean field (where the real values
23
+ # are true and false), you will want to use <tt>validates_inclusion_of :field_name,
24
+ # :in => [true, false]</tt>.
24
25
  #
25
- # This is due to the way Object#blank? handles boolean values: <tt>false.blank? # => true</tt>.
26
+ # This is due to the way Object#blank? handles boolean values:
27
+ # <tt>false.blank? # => true</tt>.
26
28
  #
27
29
  # Configuration options:
28
30
  # * <tt>:message</tt> - A custom error message (default is: "can't be blank").
29
31
  # * <tt>:on</tt> - Specifies when this validation is active. Runs in all
30
32
  # validation contexts by default (+nil+), other options are <tt>:create</tt>
31
33
  # and <tt>:update</tt>.
32
- # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
33
- # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>).
34
- # The method, proc or string should return or evaluate to a true or false value.
35
- # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
36
- # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>).
37
- # The method, proc or string should return or evaluate to a true or false value.
34
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if
35
+ # the validation should occur (e.g. <tt>:if => :allow_validation</tt>, or
36
+ # <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The method, proc
37
+ # or string should return or evaluate to a true or false value.
38
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine
39
+ # if the validation should not occur (e.g. <tt>:unless => :skip_validation</tt>,
40
+ # or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The method,
41
+ # proc or string should return or evaluate to a true or false value.
38
42
  # * <tt>:strict</tt> - Specifies whether validation should be strict.
39
- # See <tt>ActiveModel::Validation#validates!</tt> for more information
40
- #
43
+ # See <tt>ActiveModel::Validation#validates!</tt> for more information.
41
44
  def validates_presence_of(*attr_names)
42
45
  validates_with PresenceValidator, _merge_attributes(attr_names)
43
46
  end
@@ -54,15 +54,14 @@ module ActiveModel
54
54
  # (<tt>:create</tt> or <tt>:update</tt>
55
55
  # * <tt>:if</tt> - Specifies a method, proc or string to call to determine
56
56
  # if the validation should occur (e.g. <tt>:if => :allow_validation</tt>,
57
- # or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>).
58
- # The method, proc or string should return or evaluate to a true or false value.
59
- # * <tt>:unless</tt> - Specifies a method, proc or string to call to
60
- # determine if the validation should not occur
61
- # (e.g. <tt>:unless => :skip_validation</tt>, or
62
- # <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>).
63
- # The method, proc or string should return or evaluate to a true or false value.
57
+ # or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The method,
58
+ # proc or string should return or evaluate to a true or false value.
59
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine
60
+ # if the validation should not occur (e.g. <tt>:unless => :skip_validation</tt>,
61
+ # or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The method,
62
+ # proc or string should return or evaluate to a true or false value.
64
63
  # * <tt>:strict</tt> - Specifies whether validation should be strict.
65
- # See <tt>ActiveModel::Validation#validates!</tt> for more information
64
+ # See <tt>ActiveModel::Validation#validates!</tt> for more information.
66
65
 
67
66
  # If you pass any additional configuration options, they will be passed
68
67
  # to the class and available as <tt>options</tt>:
@@ -77,7 +76,6 @@ module ActiveModel
77
76
  # options[:my_custom_key] # => "my custom value"
78
77
  # end
79
78
  # end
80
- #
81
79
  def validates_with(*args, &block)
82
80
  options = args.extract_options!
83
81
  args.each do |klass|
@@ -128,12 +126,11 @@ module ActiveModel
128
126
  # Standard configuration options (:on, :if and :unless), which are
129
127
  # available on the class version of validates_with, should instead be
130
128
  # placed on the <tt>validates</tt> method as these are applied and tested
131
- # in the callback
129
+ # in the callback.
132
130
  #
133
131
  # If you pass any additional configuration options, they will be passed
134
132
  # to the class and available as <tt>options</tt>, please refer to the
135
- # class version of this method for more information
136
- #
133
+ # class version of this method for more information.
137
134
  def validates_with(*args, &block)
138
135
  options = args.extract_options!
139
136
  args.each do |klass|
@@ -2,8 +2,8 @@ module ActiveModel
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
4
  MINOR = 2
5
- TINY = 3
6
- PRE = nil
5
+ TINY = 4
6
+ PRE = "rc1"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9
9
  end
metadata CHANGED
@@ -1,13 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemodel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
5
- prerelease: false
4
+ hash: 4070160679
5
+ prerelease: 6
6
6
  segments:
7
7
  - 3
8
8
  - 2
9
- - 3
10
- version: 3.2.3
9
+ - 4
10
+ - rc
11
+ - 1
12
+ version: 3.2.4.rc1
11
13
  platform: ruby
12
14
  authors:
13
15
  - David Heinemeier Hansson
@@ -15,27 +17,30 @@ autorequire:
15
17
  bindir: bin
16
18
  cert_chain: []
17
19
 
18
- date: 2012-03-30 00:00:00 -03:00
19
- default_executable:
20
+ date: 2012-05-28 00:00:00 Z
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
- version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ name: activesupport
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
23
26
  none: false
24
27
  requirements:
25
28
  - - "="
26
29
  - !ruby/object:Gem::Version
27
- hash: 9
30
+ hash: 4070160679
28
31
  segments:
29
32
  - 3
30
33
  - 2
31
- - 3
32
- version: 3.2.3
33
- requirement: *id001
34
+ - 4
35
+ - rc
36
+ - 1
37
+ version: 3.2.4.rc1
34
38
  type: :runtime
35
- name: activesupport
36
- prerelease: false
39
+ version_requirements: *id001
37
40
  - !ruby/object:Gem::Dependency
38
- version_requirements: &id002 !ruby/object:Gem::Requirement
41
+ name: builder
42
+ prerelease: false
43
+ requirement: &id002 !ruby/object:Gem::Requirement
39
44
  none: false
40
45
  requirements:
41
46
  - - ~>
@@ -46,10 +51,8 @@ dependencies:
46
51
  - 0
47
52
  - 0
48
53
  version: 3.0.0
49
- requirement: *id002
50
54
  type: :runtime
51
- name: builder
52
- prerelease: false
55
+ version_requirements: *id002
53
56
  description: A toolkit for building modeling frameworks like Active Record and Active Resource. Rich support for attributes, callbacks, validations, observers, serialization, internationalization, and testing.
54
57
  email: david@loudthinking.com
55
58
  executables: []
@@ -97,7 +100,6 @@ files:
97
100
  - lib/active_model/validator.rb
98
101
  - lib/active_model/version.rb
99
102
  - lib/active_model.rb
100
- has_rdoc: true
101
103
  homepage: http://www.rubyonrails.org
102
104
  licenses: []
103
105
 
@@ -120,16 +122,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
122
  required_rubygems_version: !ruby/object:Gem::Requirement
121
123
  none: false
122
124
  requirements:
123
- - - ">="
125
+ - - ">"
124
126
  - !ruby/object:Gem::Version
125
- hash: 3
127
+ hash: 25
126
128
  segments:
127
- - 0
128
- version: "0"
129
+ - 1
130
+ - 3
131
+ - 1
132
+ version: 1.3.1
129
133
  requirements: []
130
134
 
131
135
  rubyforge_project:
132
- rubygems_version: 1.3.7
136
+ rubygems_version: 1.8.22
133
137
  signing_key:
134
138
  specification_version: 3
135
139
  summary: A toolkit for building modeling frameworks (part of Rails).