activemodel 7.0.8.7 → 7.2.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +38 -249
- data/MIT-LICENSE +1 -1
- data/README.rdoc +19 -19
- data/lib/active_model/access.rb +16 -0
- data/lib/active_model/api.rb +5 -5
- data/lib/active_model/attribute/user_provided_default.rb +4 -0
- data/lib/active_model/attribute.rb +27 -2
- data/lib/active_model/attribute_assignment.rb +5 -3
- data/lib/active_model/attribute_methods.rb +145 -85
- data/lib/active_model/attribute_registration.rb +117 -0
- data/lib/active_model/attribute_set.rb +10 -1
- data/lib/active_model/attributes.rb +78 -48
- data/lib/active_model/callbacks.rb +6 -6
- data/lib/active_model/conversion.rb +14 -4
- data/lib/active_model/deprecator.rb +7 -0
- data/lib/active_model/dirty.rb +134 -13
- data/lib/active_model/error.rb +4 -3
- data/lib/active_model/errors.rb +37 -6
- data/lib/active_model/forbidden_attributes_protection.rb +2 -0
- data/lib/active_model/gem_version.rb +4 -4
- data/lib/active_model/lint.rb +1 -1
- data/lib/active_model/locale/en.yml +1 -0
- data/lib/active_model/model.rb +34 -2
- data/lib/active_model/naming.rb +29 -10
- data/lib/active_model/railtie.rb +4 -0
- data/lib/active_model/secure_password.rb +63 -25
- data/lib/active_model/serialization.rb +3 -3
- data/lib/active_model/serializers/json.rb +1 -1
- data/lib/active_model/translation.rb +30 -16
- data/lib/active_model/type/big_integer.rb +23 -1
- data/lib/active_model/type/binary.rb +7 -1
- data/lib/active_model/type/boolean.rb +11 -9
- data/lib/active_model/type/date.rb +28 -2
- data/lib/active_model/type/date_time.rb +45 -3
- data/lib/active_model/type/decimal.rb +39 -1
- data/lib/active_model/type/float.rb +30 -1
- data/lib/active_model/type/helpers/accepts_multiparameter_time.rb +5 -1
- data/lib/active_model/type/helpers/numeric.rb +6 -1
- data/lib/active_model/type/helpers/time_value.rb +50 -13
- data/lib/active_model/type/helpers/timezone.rb +5 -1
- data/lib/active_model/type/immutable_string.rb +37 -1
- data/lib/active_model/type/integer.rb +44 -1
- data/lib/active_model/type/registry.rb +2 -3
- data/lib/active_model/type/serialize_cast_value.rb +47 -0
- data/lib/active_model/type/string.rb +9 -1
- data/lib/active_model/type/time.rb +48 -7
- data/lib/active_model/type/value.rb +17 -1
- data/lib/active_model/type.rb +1 -0
- data/lib/active_model/validations/absence.rb +1 -1
- data/lib/active_model/validations/acceptance.rb +1 -1
- data/lib/active_model/validations/callbacks.rb +5 -5
- data/lib/active_model/validations/clusivity.rb +5 -8
- data/lib/active_model/validations/comparability.rb +0 -11
- data/lib/active_model/validations/comparison.rb +16 -8
- data/lib/active_model/validations/format.rb +6 -7
- data/lib/active_model/validations/length.rb +10 -8
- data/lib/active_model/validations/numericality.rb +35 -23
- data/lib/active_model/validations/presence.rb +1 -1
- data/lib/active_model/validations/resolve_value.rb +26 -0
- data/lib/active_model/validations/validates.rb +4 -4
- data/lib/active_model/validations/with.rb +9 -2
- data/lib/active_model/validations.rb +48 -11
- data/lib/active_model/validator.rb +7 -5
- data/lib/active_model/version.rb +1 -1
- data/lib/active_model.rb +5 -1
- metadata +14 -12
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "active_model/validations/resolve_value"
|
|
4
|
+
|
|
3
5
|
module ActiveModel
|
|
4
6
|
module Validations
|
|
5
7
|
class LengthValidator < EachValidator # :nodoc:
|
|
8
|
+
include ResolveValue
|
|
9
|
+
|
|
6
10
|
MESSAGES = { is: :wrong_length, minimum: :too_short, maximum: :too_long }.freeze
|
|
7
11
|
CHECKS = { is: :==, minimum: :>=, maximum: :<= }.freeze
|
|
8
12
|
|
|
@@ -11,7 +15,8 @@ module ActiveModel
|
|
|
11
15
|
def initialize(options)
|
|
12
16
|
if range = (options.delete(:in) || options.delete(:within))
|
|
13
17
|
raise ArgumentError, ":in and :within must be a Range" unless range.is_a?(Range)
|
|
14
|
-
options[:minimum]
|
|
18
|
+
options[:minimum] = range.min if range.begin
|
|
19
|
+
options[:maximum] = (range.exclude_end? ? range.end - 1 : range.end) if range.end
|
|
15
20
|
end
|
|
16
21
|
|
|
17
22
|
if options[:allow_blank] == false && options[:minimum].nil? && options[:is].nil?
|
|
@@ -31,7 +36,9 @@ module ActiveModel
|
|
|
31
36
|
keys.each do |key|
|
|
32
37
|
value = options[key]
|
|
33
38
|
|
|
34
|
-
unless (value.is_a?(Integer) && value >= 0) ||
|
|
39
|
+
unless (value.is_a?(Integer) && value >= 0) ||
|
|
40
|
+
value == Float::INFINITY || value == -Float::INFINITY ||
|
|
41
|
+
value.is_a?(Symbol) || value.is_a?(Proc)
|
|
35
42
|
raise ArgumentError, ":#{key} must be a non-negative Integer, Infinity, Symbol, or Proc"
|
|
36
43
|
end
|
|
37
44
|
end
|
|
@@ -45,12 +52,7 @@ module ActiveModel
|
|
|
45
52
|
next unless check_value = options[key]
|
|
46
53
|
|
|
47
54
|
if !value.nil? || skip_nil_check?(key)
|
|
48
|
-
|
|
49
|
-
when Proc
|
|
50
|
-
check_value = check_value.call(record)
|
|
51
|
-
when Symbol
|
|
52
|
-
check_value = record.send(check_value)
|
|
53
|
-
end
|
|
55
|
+
check_value = resolve_value(record, check_value)
|
|
54
56
|
next if value_length.public_send(validity_check, check_value)
|
|
55
57
|
end
|
|
56
58
|
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "active_model/validations/comparability"
|
|
4
|
+
require "active_model/validations/resolve_value"
|
|
4
5
|
require "bigdecimal/util"
|
|
5
6
|
|
|
6
7
|
module ActiveModel
|
|
7
8
|
module Validations
|
|
8
9
|
class NumericalityValidator < EachValidator # :nodoc:
|
|
9
10
|
include Comparability
|
|
11
|
+
include ResolveValue
|
|
10
12
|
|
|
11
13
|
RANGE_CHECKS = { in: :in? }
|
|
12
14
|
NUMBER_CHECKS = { odd: :odd?, even: :even? }
|
|
13
15
|
|
|
14
|
-
RESERVED_OPTIONS = COMPARE_CHECKS.keys + NUMBER_CHECKS.keys + RANGE_CHECKS.keys + [:only_integer]
|
|
16
|
+
RESERVED_OPTIONS = COMPARE_CHECKS.keys + NUMBER_CHECKS.keys + RANGE_CHECKS.keys + [:only_integer, :only_numeric]
|
|
15
17
|
|
|
16
18
|
INTEGER_REGEX = /\A[+-]?\d+\z/
|
|
17
19
|
|
|
@@ -64,7 +66,7 @@ module ActiveModel
|
|
|
64
66
|
|
|
65
67
|
private
|
|
66
68
|
def option_as_number(record, option_value, precision, scale)
|
|
67
|
-
parse_as_number(
|
|
69
|
+
parse_as_number(resolve_value(record, option_value), precision, scale)
|
|
68
70
|
end
|
|
69
71
|
|
|
70
72
|
def parse_as_number(raw_value, precision, scale)
|
|
@@ -90,6 +92,10 @@ module ActiveModel
|
|
|
90
92
|
end
|
|
91
93
|
|
|
92
94
|
def is_number?(raw_value, precision, scale)
|
|
95
|
+
if options[:only_numeric] && !raw_value.is_a?(Numeric)
|
|
96
|
+
return false
|
|
97
|
+
end
|
|
98
|
+
|
|
93
99
|
!parse_as_number(raw_value, precision, scale).nil?
|
|
94
100
|
rescue ArgumentError, TypeError
|
|
95
101
|
false
|
|
@@ -110,14 +116,7 @@ module ActiveModel
|
|
|
110
116
|
end
|
|
111
117
|
|
|
112
118
|
def allow_only_integer?(record)
|
|
113
|
-
|
|
114
|
-
when Symbol
|
|
115
|
-
record.send(options[:only_integer])
|
|
116
|
-
when Proc
|
|
117
|
-
options[:only_integer].call(record)
|
|
118
|
-
else
|
|
119
|
-
options[:only_integer]
|
|
120
|
-
end
|
|
119
|
+
resolve_value(record, options[:only_integer])
|
|
121
120
|
end
|
|
122
121
|
|
|
123
122
|
def prepare_value_for_validation(value, record, attr_name)
|
|
@@ -149,10 +148,11 @@ module ActiveModel
|
|
|
149
148
|
|
|
150
149
|
module HelperMethods
|
|
151
150
|
# Validates whether the value of the specified attribute is numeric by
|
|
152
|
-
# trying to convert it to a float with Kernel.Float (if
|
|
153
|
-
# is +false+) or applying it to the regular
|
|
154
|
-
# (if <tt>only_integer</tt> is set to
|
|
155
|
-
# are guaranteed up to 15
|
|
151
|
+
# trying to convert it to a float with +Kernel.Float+ (if
|
|
152
|
+
# <tt>only_integer</tt> is +false+) or applying it to the regular
|
|
153
|
+
# expression <tt>/\A[\+\-]?\d+\z/</tt> (if <tt>only_integer</tt> is set to
|
|
154
|
+
# +true+). Precision of +Kernel.Float+ values are guaranteed up to 15
|
|
155
|
+
# digits.
|
|
156
156
|
#
|
|
157
157
|
# class Person < ActiveRecord::Base
|
|
158
158
|
# validates_numericality_of :value, on: :create
|
|
@@ -162,24 +162,36 @@ module ActiveModel
|
|
|
162
162
|
# * <tt>:message</tt> - A custom error message (default is: "is not a number").
|
|
163
163
|
# * <tt>:only_integer</tt> - Specifies whether the value has to be an
|
|
164
164
|
# integer (default is +false+).
|
|
165
|
+
# * <tt>:only_numeric</tt> - Specifies whether the value has to be an
|
|
166
|
+
# instance of Numeric (default is +false+). The default behavior is to
|
|
167
|
+
# attempt parsing the value if it is a String.
|
|
165
168
|
# * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+ (default is
|
|
166
169
|
# +false+). Notice that for Integer and Float columns empty strings are
|
|
167
170
|
# converted to +nil+.
|
|
168
171
|
# * <tt>:greater_than</tt> - Specifies the value must be greater than the
|
|
169
|
-
# supplied value.
|
|
172
|
+
# supplied value. The default error message for this option is _"must be
|
|
173
|
+
# greater than %{count}"_.
|
|
170
174
|
# * <tt>:greater_than_or_equal_to</tt> - Specifies the value must be
|
|
171
|
-
# greater than or equal the supplied value.
|
|
175
|
+
# greater than or equal the supplied value. The default error message
|
|
176
|
+
# for this option is _"must be greater than or equal to %{count}"_.
|
|
172
177
|
# * <tt>:equal_to</tt> - Specifies the value must be equal to the supplied
|
|
173
|
-
# value.
|
|
178
|
+
# value. The default error message for this option is _"must be equal to
|
|
179
|
+
# %{count}"_.
|
|
174
180
|
# * <tt>:less_than</tt> - Specifies the value must be less than the
|
|
175
|
-
# supplied value.
|
|
181
|
+
# supplied value. The default error message for this option is _"must be
|
|
182
|
+
# less than %{count}"_.
|
|
176
183
|
# * <tt>:less_than_or_equal_to</tt> - Specifies the value must be less
|
|
177
|
-
# than or equal the supplied value.
|
|
184
|
+
# than or equal the supplied value. The default error message for this
|
|
185
|
+
# option is _"must be less than or equal to %{count}"_.
|
|
178
186
|
# * <tt>:other_than</tt> - Specifies the value must be other than the
|
|
179
|
-
# supplied value.
|
|
180
|
-
#
|
|
181
|
-
# * <tt>:
|
|
182
|
-
#
|
|
187
|
+
# supplied value. The default error message for this option is _"must be
|
|
188
|
+
# other than %{count}"_.
|
|
189
|
+
# * <tt>:odd</tt> - Specifies the value must be an odd number. The default
|
|
190
|
+
# error message for this option is _"must be odd"_.
|
|
191
|
+
# * <tt>:even</tt> - Specifies the value must be an even number. The
|
|
192
|
+
# default error message for this option is _"must be even"_.
|
|
193
|
+
# * <tt>:in</tt> - Check that the value is within a range. The default
|
|
194
|
+
# error message for this option is _"must be in %{count}"_.
|
|
183
195
|
#
|
|
184
196
|
# There is also a list of default options supported by every validator:
|
|
185
197
|
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+ .
|
|
@@ -10,7 +10,7 @@ module ActiveModel
|
|
|
10
10
|
|
|
11
11
|
module HelperMethods
|
|
12
12
|
# Validates that the specified attributes are not blank (as defined by
|
|
13
|
-
# Object#blank?).
|
|
13
|
+
# Object#blank?).
|
|
14
14
|
#
|
|
15
15
|
# class Person < ActiveRecord::Base
|
|
16
16
|
# validates_presence_of :first_name
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActiveModel
|
|
4
|
+
module Validations
|
|
5
|
+
module ResolveValue # :nodoc:
|
|
6
|
+
def resolve_value(record, value)
|
|
7
|
+
case value
|
|
8
|
+
when Proc
|
|
9
|
+
if value.arity == 0
|
|
10
|
+
value.call
|
|
11
|
+
else
|
|
12
|
+
value.call(record)
|
|
13
|
+
end
|
|
14
|
+
when Symbol
|
|
15
|
+
record.send(value)
|
|
16
|
+
else
|
|
17
|
+
if value.respond_to?(:call)
|
|
18
|
+
value.call(record)
|
|
19
|
+
else
|
|
20
|
+
value
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -6,11 +6,11 @@ module ActiveModel
|
|
|
6
6
|
module Validations
|
|
7
7
|
module ClassMethods
|
|
8
8
|
# This method is a shortcut to all default validators and any custom
|
|
9
|
-
# validator classes ending in 'Validator'. Note that Rails default
|
|
9
|
+
# validator classes ending in 'Validator'. Note that \Rails default
|
|
10
10
|
# validators can be overridden inside specific classes by creating
|
|
11
11
|
# custom validator classes in their place such as PresenceValidator.
|
|
12
12
|
#
|
|
13
|
-
# Examples of using the default
|
|
13
|
+
# Examples of using the default Rails validators:
|
|
14
14
|
#
|
|
15
15
|
# validates :username, absence: true
|
|
16
16
|
# validates :terms, acceptance: true
|
|
@@ -116,7 +116,7 @@ module ActiveModel
|
|
|
116
116
|
key = "#{key.to_s.camelize}Validator"
|
|
117
117
|
|
|
118
118
|
begin
|
|
119
|
-
validator =
|
|
119
|
+
validator = const_get(key)
|
|
120
120
|
rescue NameError
|
|
121
121
|
raise ArgumentError, "Unknown validator: '#{key}'"
|
|
122
122
|
end
|
|
@@ -130,7 +130,7 @@ module ActiveModel
|
|
|
130
130
|
# This method is used to define validations that cannot be corrected by end
|
|
131
131
|
# users and are considered exceptional. So each validator defined with bang
|
|
132
132
|
# or <tt>:strict</tt> option set to <tt>true</tt> will always raise
|
|
133
|
-
#
|
|
133
|
+
# ActiveModel::StrictValidationFailed instead of adding error
|
|
134
134
|
# when validation fails. See <tt>validates</tt> for more information about
|
|
135
135
|
# the validation itself.
|
|
136
136
|
#
|
|
@@ -45,6 +45,13 @@ module ActiveModel
|
|
|
45
45
|
# validates_with MyValidator, MyOtherValidator, on: :create
|
|
46
46
|
# end
|
|
47
47
|
#
|
|
48
|
+
# There is no default error message for +validates_with+. You must
|
|
49
|
+
# manually add errors to the record's errors collection in the validator
|
|
50
|
+
# class.
|
|
51
|
+
#
|
|
52
|
+
# To implement the validate method, you must have a +record+ parameter
|
|
53
|
+
# defined, which is the record to be validated.
|
|
54
|
+
#
|
|
48
55
|
# Configuration options:
|
|
49
56
|
# * <tt>:on</tt> - Specifies the contexts where this validation is active.
|
|
50
57
|
# Runs in all validation contexts by default +nil+. You can pass a symbol
|
|
@@ -83,7 +90,7 @@ module ActiveModel
|
|
|
83
90
|
options[:class] = self
|
|
84
91
|
|
|
85
92
|
args.each do |klass|
|
|
86
|
-
validator = klass.new(options, &block)
|
|
93
|
+
validator = klass.new(options.dup, &block)
|
|
87
94
|
|
|
88
95
|
if validator.respond_to?(:attributes) && !validator.attributes.empty?
|
|
89
96
|
validator.attributes.each do |attribute|
|
|
@@ -139,7 +146,7 @@ module ActiveModel
|
|
|
139
146
|
options[:class] = self.class
|
|
140
147
|
|
|
141
148
|
args.each do |klass|
|
|
142
|
-
validator = klass.new(options, &block)
|
|
149
|
+
validator = klass.new(options.dup, &block)
|
|
143
150
|
validator.validate(self)
|
|
144
151
|
end
|
|
145
152
|
end
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require "active_support/core_ext/array/extract_options"
|
|
4
4
|
|
|
5
5
|
module ActiveModel
|
|
6
|
-
#
|
|
6
|
+
# = Active \Model \Validations
|
|
7
7
|
#
|
|
8
8
|
# Provides a full validation framework to your objects.
|
|
9
9
|
#
|
|
@@ -31,7 +31,7 @@ module ActiveModel
|
|
|
31
31
|
# person.invalid? # => true
|
|
32
32
|
# person.errors.messages # => {first_name:["starts with z."]}
|
|
33
33
|
#
|
|
34
|
-
# Note that
|
|
34
|
+
# Note that +ActiveModel::Validations+ automatically adds an +errors+
|
|
35
35
|
# method to your instances initialized with a new ActiveModel::Errors
|
|
36
36
|
# object, so there is no need for you to do this manually.
|
|
37
37
|
module Validations
|
|
@@ -45,6 +45,25 @@ module ActiveModel
|
|
|
45
45
|
extend HelperMethods
|
|
46
46
|
include HelperMethods
|
|
47
47
|
|
|
48
|
+
##
|
|
49
|
+
# :method: validation_context
|
|
50
|
+
# Returns the context when running validations.
|
|
51
|
+
#
|
|
52
|
+
# This is useful when running validations except a certain context (opposite to the +on+ option).
|
|
53
|
+
#
|
|
54
|
+
# class Person
|
|
55
|
+
# include ActiveModel::Validations
|
|
56
|
+
#
|
|
57
|
+
# attr_accessor :name
|
|
58
|
+
# validates :name, presence: true, if: -> { validation_context != :custom }
|
|
59
|
+
# end
|
|
60
|
+
#
|
|
61
|
+
# person = Person.new
|
|
62
|
+
# person.valid? #=> false
|
|
63
|
+
# person.valid?(:new) #=> false
|
|
64
|
+
# person.valid?(:custom) #=> true
|
|
65
|
+
|
|
66
|
+
##
|
|
48
67
|
attr_accessor :validation_context
|
|
49
68
|
private :validation_context=
|
|
50
69
|
define_callbacks :validate, scope: :name
|
|
@@ -65,7 +84,8 @@ module ActiveModel
|
|
|
65
84
|
# end
|
|
66
85
|
# end
|
|
67
86
|
#
|
|
68
|
-
# Options
|
|
87
|
+
# ==== Options
|
|
88
|
+
#
|
|
69
89
|
# * <tt>:on</tt> - Specifies the contexts where this validation is active.
|
|
70
90
|
# Runs in all validation contexts by default +nil+. You can pass a symbol
|
|
71
91
|
# or an array of symbols. (e.g. <tt>on: :create</tt> or
|
|
@@ -131,7 +151,8 @@ module ActiveModel
|
|
|
131
151
|
# Note that the return value of validation methods is not relevant.
|
|
132
152
|
# It's not possible to halt the validate callback chain.
|
|
133
153
|
#
|
|
134
|
-
# Options
|
|
154
|
+
# ==== Options
|
|
155
|
+
#
|
|
135
156
|
# * <tt>:on</tt> - Specifies the contexts where this validation is active.
|
|
136
157
|
# Runs in all validation contexts by default +nil+. You can pass a symbol
|
|
137
158
|
# or an array of symbols. (e.g. <tt>on: :create</tt> or
|
|
@@ -161,12 +182,7 @@ module ActiveModel
|
|
|
161
182
|
end
|
|
162
183
|
|
|
163
184
|
if options.key?(:on)
|
|
164
|
-
options = options.
|
|
165
|
-
options[:on] = Array(options[:on])
|
|
166
|
-
options[:if] = [
|
|
167
|
-
->(o) { !(options[:on] & Array(o.validation_context)).empty? },
|
|
168
|
-
*options[:if]
|
|
169
|
-
]
|
|
185
|
+
options = options.merge(if: [predicate_for_validation_context(options[:on]), *options[:if]])
|
|
170
186
|
end
|
|
171
187
|
|
|
172
188
|
set_callback(:validate, *args, options, &block)
|
|
@@ -277,6 +293,21 @@ module ActiveModel
|
|
|
277
293
|
base._validators = dup.each { |k, v| dup[k] = v.dup }
|
|
278
294
|
super
|
|
279
295
|
end
|
|
296
|
+
|
|
297
|
+
private
|
|
298
|
+
@@predicates_for_validation_contexts = {}
|
|
299
|
+
|
|
300
|
+
def predicate_for_validation_context(context)
|
|
301
|
+
context = context.is_a?(Array) ? context.sort : Array(context)
|
|
302
|
+
|
|
303
|
+
@@predicates_for_validation_contexts[context] ||= -> (model) do
|
|
304
|
+
if model.validation_context.is_a?(Array)
|
|
305
|
+
model.validation_context.any? { |model_context| context.include?(model_context) }
|
|
306
|
+
else
|
|
307
|
+
context.include?(model.validation_context)
|
|
308
|
+
end
|
|
309
|
+
end
|
|
310
|
+
end
|
|
280
311
|
end
|
|
281
312
|
|
|
282
313
|
# Clean the +Errors+ object if instance is duped.
|
|
@@ -402,6 +433,12 @@ module ActiveModel
|
|
|
402
433
|
alias :read_attribute_for_validation :send
|
|
403
434
|
|
|
404
435
|
private
|
|
436
|
+
def init_internals
|
|
437
|
+
super
|
|
438
|
+
@errors = nil
|
|
439
|
+
@validation_context = nil
|
|
440
|
+
end
|
|
441
|
+
|
|
405
442
|
def run_validations!
|
|
406
443
|
_run_validate_callbacks
|
|
407
444
|
errors.empty?
|
|
@@ -412,7 +449,7 @@ module ActiveModel
|
|
|
412
449
|
end
|
|
413
450
|
end
|
|
414
451
|
|
|
415
|
-
# = Active Model ValidationError
|
|
452
|
+
# = Active \Model \ValidationError
|
|
416
453
|
#
|
|
417
454
|
# Raised by <tt>validate!</tt> when the model is invalid. Use the
|
|
418
455
|
# +model+ method to retrieve the record which did not validate.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require "active_support/core_ext/module/anonymous"
|
|
4
4
|
|
|
5
5
|
module ActiveModel
|
|
6
|
-
#
|
|
6
|
+
# = Active \Model \Validator
|
|
7
7
|
#
|
|
8
8
|
# A simple base class that can be used along with
|
|
9
9
|
# ActiveModel::Validations::ClassMethods.validates_with
|
|
@@ -26,7 +26,7 @@ module ActiveModel
|
|
|
26
26
|
# end
|
|
27
27
|
# end
|
|
28
28
|
#
|
|
29
|
-
# Any class that inherits from ActiveModel::Validator must implement a method
|
|
29
|
+
# Any class that inherits from \ActiveModel::Validator must implement a method
|
|
30
30
|
# called +validate+ which accepts a +record+.
|
|
31
31
|
#
|
|
32
32
|
# class Person
|
|
@@ -65,7 +65,7 @@ module ActiveModel
|
|
|
65
65
|
# life cycle, and not on each validation run.
|
|
66
66
|
#
|
|
67
67
|
# The easiest way to add custom validators for validating individual attributes
|
|
68
|
-
# is with the convenient ActiveModel::EachValidator.
|
|
68
|
+
# is with the convenient ActiveModel::EachValidator class.
|
|
69
69
|
#
|
|
70
70
|
# class TitleValidator < ActiveModel::EachValidator
|
|
71
71
|
# def validate_each(record, attribute, value)
|
|
@@ -73,8 +73,8 @@ module ActiveModel
|
|
|
73
73
|
# end
|
|
74
74
|
# end
|
|
75
75
|
#
|
|
76
|
-
# This can now be used in combination with the +validates+ method
|
|
77
|
-
#
|
|
76
|
+
# This can now be used in combination with the +validates+ method.
|
|
77
|
+
# See ActiveModel::Validations::ClassMethods#validates for more on this.
|
|
78
78
|
#
|
|
79
79
|
# class Person
|
|
80
80
|
# include ActiveModel::Validations
|
|
@@ -124,6 +124,8 @@ module ActiveModel
|
|
|
124
124
|
end
|
|
125
125
|
end
|
|
126
126
|
|
|
127
|
+
# = Active \Model \EachValidator
|
|
128
|
+
#
|
|
127
129
|
# +EachValidator+ is a validator which iterates through the attributes given
|
|
128
130
|
# in the options hash invoking the <tt>validate_each</tt> method passing in the
|
|
129
131
|
# record, attribute, and value.
|
data/lib/active_model/version.rb
CHANGED
data/lib/active_model.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
#--
|
|
4
|
-
# Copyright (c)
|
|
4
|
+
# Copyright (c) David Heinemeier Hansson
|
|
5
5
|
#
|
|
6
6
|
# Permission is hereby granted, free of charge, to any person obtaining
|
|
7
7
|
# a copy of this software and associated documentation files (the
|
|
@@ -26,15 +26,19 @@
|
|
|
26
26
|
require "active_support"
|
|
27
27
|
require "active_support/rails"
|
|
28
28
|
require "active_model/version"
|
|
29
|
+
require "active_model/deprecator"
|
|
29
30
|
|
|
31
|
+
# :include: ../README.rdoc
|
|
30
32
|
module ActiveModel
|
|
31
33
|
extend ActiveSupport::Autoload
|
|
32
34
|
|
|
35
|
+
autoload :Access
|
|
33
36
|
autoload :API
|
|
34
37
|
autoload :Attribute
|
|
35
38
|
autoload :Attributes
|
|
36
39
|
autoload :AttributeAssignment
|
|
37
40
|
autoload :AttributeMethods
|
|
41
|
+
autoload :AttributeRegistration
|
|
38
42
|
autoload :BlockValidator, "active_model/validator"
|
|
39
43
|
autoload :Callbacks
|
|
40
44
|
autoload :Conversion
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activemodel
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 7.
|
|
4
|
+
version: 7.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Heinemeier Hansson
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activesupport
|
|
@@ -16,14 +15,14 @@ dependencies:
|
|
|
16
15
|
requirements:
|
|
17
16
|
- - '='
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 7.
|
|
18
|
+
version: 7.2.3
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
23
|
- - '='
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 7.
|
|
25
|
+
version: 7.2.3
|
|
27
26
|
description: A toolkit for building modeling frameworks like Active Record. Rich support
|
|
28
27
|
for attributes, callbacks, validations, serialization, internationalization, and
|
|
29
28
|
testing.
|
|
@@ -36,18 +35,21 @@ files:
|
|
|
36
35
|
- MIT-LICENSE
|
|
37
36
|
- README.rdoc
|
|
38
37
|
- lib/active_model.rb
|
|
38
|
+
- lib/active_model/access.rb
|
|
39
39
|
- lib/active_model/api.rb
|
|
40
40
|
- lib/active_model/attribute.rb
|
|
41
41
|
- lib/active_model/attribute/user_provided_default.rb
|
|
42
42
|
- lib/active_model/attribute_assignment.rb
|
|
43
43
|
- lib/active_model/attribute_methods.rb
|
|
44
44
|
- lib/active_model/attribute_mutation_tracker.rb
|
|
45
|
+
- lib/active_model/attribute_registration.rb
|
|
45
46
|
- lib/active_model/attribute_set.rb
|
|
46
47
|
- lib/active_model/attribute_set/builder.rb
|
|
47
48
|
- lib/active_model/attribute_set/yaml_encoder.rb
|
|
48
49
|
- lib/active_model/attributes.rb
|
|
49
50
|
- lib/active_model/callbacks.rb
|
|
50
51
|
- lib/active_model/conversion.rb
|
|
52
|
+
- lib/active_model/deprecator.rb
|
|
51
53
|
- lib/active_model/dirty.rb
|
|
52
54
|
- lib/active_model/error.rb
|
|
53
55
|
- lib/active_model/errors.rb
|
|
@@ -80,6 +82,7 @@ files:
|
|
|
80
82
|
- lib/active_model/type/immutable_string.rb
|
|
81
83
|
- lib/active_model/type/integer.rb
|
|
82
84
|
- lib/active_model/type/registry.rb
|
|
85
|
+
- lib/active_model/type/serialize_cast_value.rb
|
|
83
86
|
- lib/active_model/type/string.rb
|
|
84
87
|
- lib/active_model/type/time.rb
|
|
85
88
|
- lib/active_model/type/value.rb
|
|
@@ -98,6 +101,7 @@ files:
|
|
|
98
101
|
- lib/active_model/validations/length.rb
|
|
99
102
|
- lib/active_model/validations/numericality.rb
|
|
100
103
|
- lib/active_model/validations/presence.rb
|
|
104
|
+
- lib/active_model/validations/resolve_value.rb
|
|
101
105
|
- lib/active_model/validations/validates.rb
|
|
102
106
|
- lib/active_model/validations/with.rb
|
|
103
107
|
- lib/active_model/validator.rb
|
|
@@ -107,12 +111,11 @@ licenses:
|
|
|
107
111
|
- MIT
|
|
108
112
|
metadata:
|
|
109
113
|
bug_tracker_uri: https://github.com/rails/rails/issues
|
|
110
|
-
changelog_uri: https://github.com/rails/rails/blob/v7.
|
|
111
|
-
documentation_uri: https://api.rubyonrails.org/v7.
|
|
114
|
+
changelog_uri: https://github.com/rails/rails/blob/v7.2.3/activemodel/CHANGELOG.md
|
|
115
|
+
documentation_uri: https://api.rubyonrails.org/v7.2.3/
|
|
112
116
|
mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
|
|
113
|
-
source_code_uri: https://github.com/rails/rails/tree/v7.
|
|
117
|
+
source_code_uri: https://github.com/rails/rails/tree/v7.2.3/activemodel
|
|
114
118
|
rubygems_mfa_required: 'true'
|
|
115
|
-
post_install_message:
|
|
116
119
|
rdoc_options: []
|
|
117
120
|
require_paths:
|
|
118
121
|
- lib
|
|
@@ -120,15 +123,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
120
123
|
requirements:
|
|
121
124
|
- - ">="
|
|
122
125
|
- !ruby/object:Gem::Version
|
|
123
|
-
version:
|
|
126
|
+
version: 3.1.0
|
|
124
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
128
|
requirements:
|
|
126
129
|
- - ">="
|
|
127
130
|
- !ruby/object:Gem::Version
|
|
128
131
|
version: '0'
|
|
129
132
|
requirements: []
|
|
130
|
-
rubygems_version: 3.
|
|
131
|
-
signing_key:
|
|
133
|
+
rubygems_version: 3.6.9
|
|
132
134
|
specification_version: 4
|
|
133
135
|
summary: A toolkit for building modeling frameworks (part of Rails).
|
|
134
136
|
test_files: []
|