activemodel 7.0.4.3 → 7.0.5
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 +5 -0
- data/lib/active_model/attribute_methods.rb +30 -38
- data/lib/active_model/attribute_mutation_tracker.rb +10 -2
- data/lib/active_model/callbacks.rb +1 -1
- data/lib/active_model/gem_version.rb +2 -2
- data/lib/active_model/type/binary.rb +3 -1
- data/lib/active_model/type/helpers/mutable.rb +4 -0
- data/lib/active_model/type/value.rb +4 -0
- data/lib/active_model/validations/callbacks.rb +6 -8
- data/lib/active_model/validations/length.rb +3 -4
- data/lib/active_model/validations/validates.rb +1 -1
- data/lib/active_model.rb +1 -0
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1e260ee8a07b5c46bd04d84013855604516f92bd9d2305cd4108582963551e6
|
4
|
+
data.tar.gz: '030858442b97869a031487982dbd29c709af654e01e0e63df48b6b95e20f900a'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fef75f5d7769575131c5409a80bc17b955b43e2695f3d6425a47f99a363c49a7991f2d5ab4d7eea8908f45e2af8033ce59cf6bd163c5c9193f345040aed9f646
|
7
|
+
data.tar.gz: c1f480b1de01351da6701d5cd5452837de8a44ab01f7d5f196eaab5cb5a76b6bda7666cb4c8a79fa37743f087157431a71b2b9cd63e4609d4475c19d11d4d23f
|
data/CHANGELOG.md
CHANGED
@@ -49,18 +49,17 @@ module ActiveModel
|
|
49
49
|
# end
|
50
50
|
#
|
51
51
|
# private
|
52
|
+
# def attribute_contrived?(attr)
|
53
|
+
# true
|
54
|
+
# end
|
52
55
|
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
# def clear_attribute(attr)
|
58
|
-
# send("#{attr}=", nil)
|
59
|
-
# end
|
56
|
+
# def clear_attribute(attr)
|
57
|
+
# send("#{attr}=", nil)
|
58
|
+
# end
|
60
59
|
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
60
|
+
# def reset_attribute_to_default!(attr)
|
61
|
+
# send("#{attr}=", 'Default Name')
|
62
|
+
# end
|
64
63
|
# end
|
65
64
|
module AttributeMethods
|
66
65
|
extend ActiveSupport::Concern
|
@@ -95,10 +94,9 @@ module ActiveModel
|
|
95
94
|
# define_attribute_methods :name
|
96
95
|
#
|
97
96
|
# private
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
# end
|
97
|
+
# def clear_attribute(attr)
|
98
|
+
# send("#{attr}=", nil)
|
99
|
+
# end
|
102
100
|
# end
|
103
101
|
#
|
104
102
|
# person = Person.new
|
@@ -131,10 +129,9 @@ module ActiveModel
|
|
131
129
|
# define_attribute_methods :name
|
132
130
|
#
|
133
131
|
# private
|
134
|
-
#
|
135
|
-
#
|
136
|
-
#
|
137
|
-
# end
|
132
|
+
# def attribute_short?(attr)
|
133
|
+
# send(attr).length < 5
|
134
|
+
# end
|
138
135
|
# end
|
139
136
|
#
|
140
137
|
# person = Person.new
|
@@ -167,10 +164,9 @@ module ActiveModel
|
|
167
164
|
# define_attribute_methods :name
|
168
165
|
#
|
169
166
|
# private
|
170
|
-
#
|
171
|
-
#
|
172
|
-
#
|
173
|
-
# end
|
167
|
+
# def reset_attribute_to_default!(attr)
|
168
|
+
# send("#{attr}=", 'Default Name')
|
169
|
+
# end
|
174
170
|
# end
|
175
171
|
#
|
176
172
|
# person = Person.new
|
@@ -194,10 +190,9 @@ module ActiveModel
|
|
194
190
|
# alias_attribute :nickname, :name
|
195
191
|
#
|
196
192
|
# private
|
197
|
-
#
|
198
|
-
#
|
199
|
-
#
|
200
|
-
# end
|
193
|
+
# def attribute_short?(attr)
|
194
|
+
# send(attr).length < 5
|
195
|
+
# end
|
201
196
|
# end
|
202
197
|
#
|
203
198
|
# person = Person.new
|
@@ -268,10 +263,9 @@ module ActiveModel
|
|
268
263
|
# define_attribute_methods :name, :age, :address
|
269
264
|
#
|
270
265
|
# private
|
271
|
-
#
|
272
|
-
#
|
273
|
-
#
|
274
|
-
# end
|
266
|
+
# def clear_attribute(attr)
|
267
|
+
# send("#{attr}=", nil)
|
268
|
+
# end
|
275
269
|
# end
|
276
270
|
def define_attribute_methods(*attr_names)
|
277
271
|
ActiveSupport::CodeGenerator.batch(generated_attribute_methods, __FILE__, __LINE__) do |owner|
|
@@ -298,10 +292,9 @@ module ActiveModel
|
|
298
292
|
# define_attribute_method :name
|
299
293
|
#
|
300
294
|
# private
|
301
|
-
#
|
302
|
-
#
|
303
|
-
#
|
304
|
-
# end
|
295
|
+
# def attribute_short?(attr)
|
296
|
+
# send(attr).length < 5
|
297
|
+
# end
|
305
298
|
# end
|
306
299
|
#
|
307
300
|
# person = Person.new
|
@@ -337,10 +330,9 @@ module ActiveModel
|
|
337
330
|
# define_attribute_method :name
|
338
331
|
#
|
339
332
|
# private
|
340
|
-
#
|
341
|
-
#
|
342
|
-
#
|
343
|
-
# end
|
333
|
+
# def attribute_short?(attr)
|
334
|
+
# send(attr).length < 5
|
335
|
+
# end
|
344
336
|
# end
|
345
337
|
#
|
346
338
|
# person = Person.new
|
@@ -43,8 +43,8 @@ module ActiveModel
|
|
43
43
|
|
44
44
|
def changed?(attr_name, from: OPTION_NOT_GIVEN, to: OPTION_NOT_GIVEN)
|
45
45
|
attribute_changed?(attr_name) &&
|
46
|
-
(OPTION_NOT_GIVEN == from || original_value(attr_name) == from) &&
|
47
|
-
(OPTION_NOT_GIVEN == to || fetch_value(attr_name) == to)
|
46
|
+
(OPTION_NOT_GIVEN == from || original_value(attr_name) == type_cast(attr_name, from)) &&
|
47
|
+
(OPTION_NOT_GIVEN == to || fetch_value(attr_name) == type_cast(attr_name, to))
|
48
48
|
end
|
49
49
|
|
50
50
|
def changed_in_place?(attr_name)
|
@@ -82,6 +82,10 @@ module ActiveModel
|
|
82
82
|
def fetch_value(attr_name)
|
83
83
|
attributes.fetch_value(attr_name)
|
84
84
|
end
|
85
|
+
|
86
|
+
def type_cast(attr_name, value)
|
87
|
+
attributes[attr_name].type_cast(value)
|
88
|
+
end
|
85
89
|
end
|
86
90
|
|
87
91
|
class ForcedMutationTracker < AttributeMutationTracker # :nodoc:
|
@@ -143,6 +147,10 @@ module ActiveModel
|
|
143
147
|
rescue TypeError, NoMethodError
|
144
148
|
value
|
145
149
|
end
|
150
|
+
|
151
|
+
def type_cast(attr_name, value)
|
152
|
+
value
|
153
|
+
end
|
146
154
|
end
|
147
155
|
|
148
156
|
class NullMutationTracker # :nodoc:
|
@@ -74,7 +74,7 @@ module ActiveModel
|
|
74
74
|
# <tt>:only</tt> option, where you can choose if you want all types (before,
|
75
75
|
# around or after) or just some.
|
76
76
|
#
|
77
|
-
# define_model_callbacks :
|
77
|
+
# define_model_callbacks :initialize, only: :after
|
78
78
|
#
|
79
79
|
# Note, the <tt>only: <type></tt> hash will apply to all callbacks defined
|
80
80
|
# on that method call. To get around this you can call the define_model_callbacks
|
@@ -121,6 +121,10 @@ module ActiveModel
|
|
121
121
|
def assert_valid_value(_)
|
122
122
|
end
|
123
123
|
|
124
|
+
def immutable_value(value) # :nodoc:
|
125
|
+
value
|
126
|
+
end
|
127
|
+
|
124
128
|
private
|
125
129
|
# Convenience method for types which do not need separate type casting
|
126
130
|
# behavior for user and database inputs. Called by Value#cast for
|
@@ -43,10 +43,9 @@ module ActiveModel
|
|
43
43
|
# before_validation :remove_whitespaces
|
44
44
|
#
|
45
45
|
# private
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
# end
|
46
|
+
# def remove_whitespaces
|
47
|
+
# name.strip!
|
48
|
+
# end
|
50
49
|
# end
|
51
50
|
#
|
52
51
|
# person = Person.new
|
@@ -74,10 +73,9 @@ module ActiveModel
|
|
74
73
|
# after_validation :set_status
|
75
74
|
#
|
76
75
|
# private
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
# end
|
76
|
+
# def set_status
|
77
|
+
# self.status = errors.empty?
|
78
|
+
# end
|
81
79
|
# end
|
82
80
|
#
|
83
81
|
# person = Person.new
|
@@ -85,10 +85,9 @@ module ActiveModel
|
|
85
85
|
# validates_length_of :words_in_essay, minimum: 100, too_short: 'Your essay must be at least 100 words.'
|
86
86
|
#
|
87
87
|
# private
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
91
|
-
# end
|
88
|
+
# def words_in_essay
|
89
|
+
# essay.scan(/\w+/)
|
90
|
+
# end
|
92
91
|
# end
|
93
92
|
#
|
94
93
|
# Constraint options:
|
@@ -96,7 +96,7 @@ module ActiveModel
|
|
96
96
|
# Example:
|
97
97
|
#
|
98
98
|
# validates :password, presence: true, confirmation: true, if: :password_required?
|
99
|
-
# validates :token, length: 24, strict: TokenLengthException
|
99
|
+
# validates :token, length: { is: 24 }, strict: TokenLengthException
|
100
100
|
#
|
101
101
|
#
|
102
102
|
# Finally, the options +:if+, +:unless+, +:on+, +:allow_blank+, +:allow_nil+, +:strict+
|
data/lib/active_model.rb
CHANGED
@@ -58,6 +58,7 @@ module ActiveModel
|
|
58
58
|
autoload :RangeError, "active_model/errors"
|
59
59
|
autoload :StrictValidationFailed, "active_model/errors"
|
60
60
|
autoload :UnknownAttributeError, "active_model/errors"
|
61
|
+
autoload :ValidationError, "active_model/validations"
|
61
62
|
end
|
62
63
|
|
63
64
|
module Serializers
|
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: 7.0.
|
4
|
+
version: 7.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-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: 7.0.
|
19
|
+
version: 7.0.5
|
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: 7.0.
|
26
|
+
version: 7.0.5
|
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.
|
@@ -107,12 +107,12 @@ licenses:
|
|
107
107
|
- MIT
|
108
108
|
metadata:
|
109
109
|
bug_tracker_uri: https://github.com/rails/rails/issues
|
110
|
-
changelog_uri: https://github.com/rails/rails/blob/v7.0.
|
111
|
-
documentation_uri: https://api.rubyonrails.org/v7.0.
|
110
|
+
changelog_uri: https://github.com/rails/rails/blob/v7.0.5/activemodel/CHANGELOG.md
|
111
|
+
documentation_uri: https://api.rubyonrails.org/v7.0.5/
|
112
112
|
mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
|
113
|
-
source_code_uri: https://github.com/rails/rails/tree/v7.0.
|
113
|
+
source_code_uri: https://github.com/rails/rails/tree/v7.0.5/activemodel
|
114
114
|
rubygems_mfa_required: 'true'
|
115
|
-
post_install_message:
|
115
|
+
post_install_message:
|
116
116
|
rdoc_options: []
|
117
117
|
require_paths:
|
118
118
|
- lib
|
@@ -127,8 +127,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
- !ruby/object:Gem::Version
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
|
-
rubygems_version: 3.4.
|
131
|
-
signing_key:
|
130
|
+
rubygems_version: 3.4.10
|
131
|
+
signing_key:
|
132
132
|
specification_version: 4
|
133
133
|
summary: A toolkit for building modeling frameworks (part of Rails).
|
134
134
|
test_files: []
|