activemodel 5.2.6 → 6.1.4
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 +58 -109
- data/MIT-LICENSE +1 -1
- data/README.rdoc +6 -4
- data/lib/active_model.rb +2 -1
- data/lib/active_model/attribute.rb +21 -21
- data/lib/active_model/attribute/user_provided_default.rb +1 -2
- data/lib/active_model/attribute_assignment.rb +4 -6
- data/lib/active_model/attribute_methods.rb +117 -40
- data/lib/active_model/attribute_mutation_tracker.rb +90 -33
- data/lib/active_model/attribute_set.rb +20 -28
- data/lib/active_model/attribute_set/builder.rb +81 -16
- data/lib/active_model/attribute_set/yaml_encoder.rb +1 -2
- data/lib/active_model/attributes.rb +65 -44
- data/lib/active_model/callbacks.rb +11 -9
- data/lib/active_model/conversion.rb +1 -1
- data/lib/active_model/dirty.rb +51 -101
- data/lib/active_model/error.rb +207 -0
- data/lib/active_model/errors.rb +347 -155
- data/lib/active_model/gem_version.rb +3 -3
- data/lib/active_model/lint.rb +1 -1
- data/lib/active_model/naming.rb +22 -7
- data/lib/active_model/nested_error.rb +22 -0
- data/lib/active_model/railtie.rb +6 -0
- data/lib/active_model/secure_password.rb +54 -55
- data/lib/active_model/serialization.rb +9 -7
- data/lib/active_model/serializers/json.rb +17 -9
- data/lib/active_model/translation.rb +1 -1
- data/lib/active_model/type/big_integer.rb +0 -1
- data/lib/active_model/type/binary.rb +1 -1
- data/lib/active_model/type/boolean.rb +0 -1
- data/lib/active_model/type/date.rb +0 -5
- data/lib/active_model/type/date_time.rb +3 -8
- data/lib/active_model/type/decimal.rb +0 -1
- data/lib/active_model/type/float.rb +2 -3
- data/lib/active_model/type/helpers/accepts_multiparameter_time.rb +14 -6
- data/lib/active_model/type/helpers/numeric.rb +17 -6
- data/lib/active_model/type/helpers/time_value.rb +37 -15
- data/lib/active_model/type/helpers/timezone.rb +1 -1
- data/lib/active_model/type/immutable_string.rb +14 -11
- data/lib/active_model/type/integer.rb +15 -18
- data/lib/active_model/type/registry.rb +16 -16
- data/lib/active_model/type/string.rb +12 -3
- data/lib/active_model/type/time.rb +1 -6
- data/lib/active_model/type/value.rb +9 -2
- data/lib/active_model/validations.rb +6 -9
- data/lib/active_model/validations/absence.rb +2 -2
- data/lib/active_model/validations/acceptance.rb +34 -27
- data/lib/active_model/validations/callbacks.rb +15 -16
- data/lib/active_model/validations/clusivity.rb +6 -3
- data/lib/active_model/validations/confirmation.rb +4 -4
- data/lib/active_model/validations/exclusion.rb +1 -1
- data/lib/active_model/validations/format.rb +2 -3
- data/lib/active_model/validations/inclusion.rb +2 -2
- data/lib/active_model/validations/length.rb +3 -3
- data/lib/active_model/validations/numericality.rb +58 -44
- data/lib/active_model/validations/presence.rb +1 -1
- data/lib/active_model/validations/validates.rb +7 -6
- data/lib/active_model/validator.rb +8 -3
- metadata +14 -9
@@ -4,7 +4,7 @@ module ActiveModel
|
|
4
4
|
module Validations
|
5
5
|
class PresenceValidator < EachValidator # :nodoc:
|
6
6
|
def validate_each(record, attr_name, value)
|
7
|
-
record.errors.add(attr_name, :blank, options) if value.blank?
|
7
|
+
record.errors.add(attr_name, :blank, **options) if value.blank?
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -12,6 +12,7 @@ module ActiveModel
|
|
12
12
|
#
|
13
13
|
# Examples of using the default rails validators:
|
14
14
|
#
|
15
|
+
# validates :username, absence: true
|
15
16
|
# validates :terms, acceptance: true
|
16
17
|
# validates :password, confirmation: true
|
17
18
|
# validates :username, exclusion: { in: %w(admin superuser) }
|
@@ -27,7 +28,7 @@ module ActiveModel
|
|
27
28
|
# class EmailValidator < ActiveModel::EachValidator
|
28
29
|
# def validate_each(record, attribute, value)
|
29
30
|
# record.errors.add attribute, (options[:message] || "is not an email") unless
|
30
|
-
#
|
31
|
+
# /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i.match?(value)
|
31
32
|
# end
|
32
33
|
# end
|
33
34
|
#
|
@@ -47,7 +48,7 @@ module ActiveModel
|
|
47
48
|
#
|
48
49
|
# class TitleValidator < ActiveModel::EachValidator
|
49
50
|
# def validate_each(record, attribute, value)
|
50
|
-
# record.errors.add attribute, "must start with 'the'" unless
|
51
|
+
# record.errors.add attribute, "must start with 'the'" unless /\Athe/i.match?(value)
|
51
52
|
# end
|
52
53
|
# end
|
53
54
|
#
|
@@ -63,7 +64,7 @@ module ActiveModel
|
|
63
64
|
# and strings in shortcut form.
|
64
65
|
#
|
65
66
|
# validates :email, format: /@/
|
66
|
-
# validates :
|
67
|
+
# validates :role, inclusion: %w(admin contributor)
|
67
68
|
# validates :password, length: 6..20
|
68
69
|
#
|
69
70
|
# When using shortcut form, ranges and arrays are passed to your
|
@@ -112,15 +113,16 @@ module ActiveModel
|
|
112
113
|
defaults[:attributes] = attributes
|
113
114
|
|
114
115
|
validations.each do |key, options|
|
115
|
-
next unless options
|
116
116
|
key = "#{key.to_s.camelize}Validator"
|
117
117
|
|
118
118
|
begin
|
119
|
-
validator = key.include?("::"
|
119
|
+
validator = key.include?("::") ? key.constantize : const_get(key)
|
120
120
|
rescue NameError
|
121
121
|
raise ArgumentError, "Unknown validator: '#{key}'"
|
122
122
|
end
|
123
123
|
|
124
|
+
next unless options
|
125
|
+
|
124
126
|
validates_with(validator, defaults.merge(_parse_validates_options(options)))
|
125
127
|
end
|
126
128
|
end
|
@@ -150,7 +152,6 @@ module ActiveModel
|
|
150
152
|
end
|
151
153
|
|
152
154
|
private
|
153
|
-
|
154
155
|
# When creating custom validators, it might be useful to be able to specify
|
155
156
|
# additional default keys. This can be done by overwriting this method.
|
156
157
|
def _validates_default_keys
|
@@ -85,12 +85,12 @@ module ActiveModel
|
|
85
85
|
#
|
86
86
|
# It can be useful to access the class that is using that validator when there are prerequisites such
|
87
87
|
# as an +attr_accessor+ being present. This class is accessible via <tt>options[:class]</tt> in the constructor.
|
88
|
-
# To
|
88
|
+
# To set up your validator override the constructor.
|
89
89
|
#
|
90
90
|
# class MyValidator < ActiveModel::Validator
|
91
91
|
# def initialize(options={})
|
92
92
|
# super
|
93
|
-
# options[:class].
|
93
|
+
# options[:class].attr_accessor :custom_attribute
|
94
94
|
# end
|
95
95
|
# end
|
96
96
|
class Validator
|
@@ -149,6 +149,7 @@ module ActiveModel
|
|
149
149
|
attributes.each do |attribute|
|
150
150
|
value = record.read_attribute_for_validation(attribute)
|
151
151
|
next if (value.nil? && options[:allow_nil]) || (value.blank? && options[:allow_blank])
|
152
|
+
value = prepare_value_for_validation(value, record, attribute)
|
152
153
|
validate_each(record, attribute, value)
|
153
154
|
end
|
154
155
|
end
|
@@ -164,6 +165,11 @@ module ActiveModel
|
|
164
165
|
# +ArgumentError+ when invalid options are supplied.
|
165
166
|
def check_validity!
|
166
167
|
end
|
168
|
+
|
169
|
+
private
|
170
|
+
def prepare_value_for_validation(value, record, attr_name)
|
171
|
+
value
|
172
|
+
end
|
167
173
|
end
|
168
174
|
|
169
175
|
# +BlockValidator+ is a special +EachValidator+ which receives a block on initialization
|
@@ -175,7 +181,6 @@ module ActiveModel
|
|
175
181
|
end
|
176
182
|
|
177
183
|
private
|
178
|
-
|
179
184
|
def validate_each(record, attribute, value)
|
180
185
|
@block.call(record, attribute, value)
|
181
186
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activemodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.1.4
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.1.4
|
27
27
|
description: A toolkit for building modeling frameworks like Active Record. Rich support
|
28
28
|
for attributes, callbacks, validations, serialization, internationalization, and
|
29
29
|
testing.
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- lib/active_model/callbacks.rb
|
49
49
|
- lib/active_model/conversion.rb
|
50
50
|
- lib/active_model/dirty.rb
|
51
|
+
- lib/active_model/error.rb
|
51
52
|
- lib/active_model/errors.rb
|
52
53
|
- lib/active_model/forbidden_attributes_protection.rb
|
53
54
|
- lib/active_model/gem_version.rb
|
@@ -55,6 +56,7 @@ files:
|
|
55
56
|
- lib/active_model/locale/en.yml
|
56
57
|
- lib/active_model/model.rb
|
57
58
|
- lib/active_model/naming.rb
|
59
|
+
- lib/active_model/nested_error.rb
|
58
60
|
- lib/active_model/railtie.rb
|
59
61
|
- lib/active_model/secure_password.rb
|
60
62
|
- lib/active_model/serialization.rb
|
@@ -97,12 +99,15 @@ files:
|
|
97
99
|
- lib/active_model/validations/with.rb
|
98
100
|
- lib/active_model/validator.rb
|
99
101
|
- lib/active_model/version.rb
|
100
|
-
homepage:
|
102
|
+
homepage: https://rubyonrails.org
|
101
103
|
licenses:
|
102
104
|
- MIT
|
103
105
|
metadata:
|
104
|
-
|
105
|
-
changelog_uri: https://github.com/rails/rails/blob/
|
106
|
+
bug_tracker_uri: https://github.com/rails/rails/issues
|
107
|
+
changelog_uri: https://github.com/rails/rails/blob/v6.1.4/activemodel/CHANGELOG.md
|
108
|
+
documentation_uri: https://api.rubyonrails.org/v6.1.4/
|
109
|
+
mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
|
110
|
+
source_code_uri: https://github.com/rails/rails/tree/v6.1.4/activemodel
|
106
111
|
post_install_message:
|
107
112
|
rdoc_options: []
|
108
113
|
require_paths:
|
@@ -111,14 +116,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
116
|
requirements:
|
112
117
|
- - ">="
|
113
118
|
- !ruby/object:Gem::Version
|
114
|
-
version: 2.
|
119
|
+
version: 2.5.0
|
115
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
121
|
requirements:
|
117
122
|
- - ">="
|
118
123
|
- !ruby/object:Gem::Version
|
119
124
|
version: '0'
|
120
125
|
requirements: []
|
121
|
-
rubygems_version: 3.1.
|
126
|
+
rubygems_version: 3.1.2
|
122
127
|
signing_key:
|
123
128
|
specification_version: 4
|
124
129
|
summary: A toolkit for building modeling frameworks (part of Rails).
|