activemodel 6.0.6.1 → 6.1.7.6
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 +97 -162
- data/MIT-LICENSE +1 -2
- data/README.rdoc +1 -1
- data/lib/active_model/attribute.rb +18 -17
- data/lib/active_model/attribute_assignment.rb +3 -4
- data/lib/active_model/attribute_methods.rb +74 -38
- data/lib/active_model/attribute_mutation_tracker.rb +8 -5
- data/lib/active_model/attribute_set/builder.rb +80 -13
- data/lib/active_model/attribute_set.rb +18 -16
- data/lib/active_model/attributes.rb +20 -24
- data/lib/active_model/callbacks.rb +1 -1
- data/lib/active_model/dirty.rb +17 -4
- data/lib/active_model/error.rb +207 -0
- data/lib/active_model/errors.rb +316 -208
- data/lib/active_model/gem_version.rb +3 -3
- data/lib/active_model/lint.rb +1 -1
- data/lib/active_model/naming.rb +2 -2
- data/lib/active_model/nested_error.rb +22 -0
- data/lib/active_model/railtie.rb +1 -1
- data/lib/active_model/secure_password.rb +15 -14
- data/lib/active_model/serialization.rb +9 -6
- data/lib/active_model/serializers/json.rb +7 -0
- data/lib/active_model/type/date_time.rb +2 -2
- data/lib/active_model/type/float.rb +2 -0
- data/lib/active_model/type/helpers/accepts_multiparameter_time.rb +11 -7
- data/lib/active_model/type/helpers/numeric.rb +8 -3
- data/lib/active_model/type/helpers/time_value.rb +27 -17
- data/lib/active_model/type/helpers/timezone.rb +1 -1
- data/lib/active_model/type/immutable_string.rb +14 -10
- data/lib/active_model/type/integer.rb +11 -2
- data/lib/active_model/type/registry.rb +12 -9
- data/lib/active_model/type/string.rb +12 -2
- data/lib/active_model/type/value.rb +9 -1
- data/lib/active_model/type.rb +3 -2
- 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 +15 -15
- data/lib/active_model/validations/clusivity.rb +5 -1
- data/lib/active_model/validations/confirmation.rb +2 -2
- data/lib/active_model/validations/exclusion.rb +1 -1
- data/lib/active_model/validations/format.rb +2 -2
- data/lib/active_model/validations/inclusion.rb +1 -1
- data/lib/active_model/validations/length.rb +2 -2
- data/lib/active_model/validations/numericality.rb +54 -41
- data/lib/active_model/validations/presence.rb +1 -1
- data/lib/active_model/validations/validates.rb +6 -4
- data/lib/active_model/validations.rb +6 -6
- data/lib/active_model/validator.rb +7 -1
- data/lib/active_model.rb +2 -1
- metadata +10 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c6f345a5635a5f0160a48a7dcaea942a7488a5c9f824500360eee23b09d3ba80
|
|
4
|
+
data.tar.gz: 02e8b9277ae92ddb32d80ec0dd03d0f2b9fc007feda4ddc5a2bfea3a264ed294
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 07ecfe4225bb1c2d2c7308c7f2a74cc6121c11eb6632aaea01cd82970657baedbb0ed74f601fb80a66e60b432fcc729049e809ee7b6597c31b18896e29d6cd4d
|
|
7
|
+
data.tar.gz: 0efc0b019c80c8b0665a0df671f215781118906e047af4b5414965e05fe4ab781a6b7f94fc78bea376e54cf5ebcd7a2edf897f312940d52cb61996a4cd88088c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,297 +1,232 @@
|
|
|
1
|
-
## Rails 6.
|
|
1
|
+
## Rails 6.1.7.6 (August 22, 2023) ##
|
|
2
2
|
|
|
3
3
|
* No changes.
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
## Rails 6.
|
|
6
|
+
## Rails 6.1.7.5 (August 22, 2023) ##
|
|
7
7
|
|
|
8
8
|
* No changes.
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
## Rails 6.
|
|
11
|
+
## Rails 6.1.7.4 (June 26, 2023) ##
|
|
12
12
|
|
|
13
13
|
* No changes.
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
## Rails 6.
|
|
16
|
+
## Rails 6.1.7.3 (March 13, 2023) ##
|
|
17
17
|
|
|
18
18
|
* No changes.
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
## Rails 6.
|
|
21
|
+
## Rails 6.1.7.2 (January 24, 2023) ##
|
|
22
22
|
|
|
23
23
|
* No changes.
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
## Rails 6.
|
|
26
|
+
## Rails 6.1.7.1 (January 17, 2023) ##
|
|
27
27
|
|
|
28
28
|
* No changes.
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
## Rails 6.
|
|
31
|
+
## Rails 6.1.7 (September 09, 2022) ##
|
|
32
32
|
|
|
33
33
|
* No changes.
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
## Rails 6.
|
|
36
|
+
## Rails 6.1.6.1 (July 12, 2022) ##
|
|
37
37
|
|
|
38
38
|
* No changes.
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
## Rails 6.
|
|
41
|
+
## Rails 6.1.6 (May 09, 2022) ##
|
|
42
42
|
|
|
43
43
|
* No changes.
|
|
44
44
|
|
|
45
45
|
|
|
46
|
-
## Rails 6.
|
|
46
|
+
## Rails 6.1.5.1 (April 26, 2022) ##
|
|
47
47
|
|
|
48
48
|
* No changes.
|
|
49
49
|
|
|
50
50
|
|
|
51
|
-
## Rails 6.
|
|
51
|
+
## Rails 6.1.5 (March 09, 2022) ##
|
|
52
52
|
|
|
53
|
-
*
|
|
53
|
+
* Clear secure password cache if password is set to `nil`
|
|
54
54
|
|
|
55
|
+
Before:
|
|
55
56
|
|
|
56
|
-
|
|
57
|
+
user.password = 'something'
|
|
58
|
+
user.password = nil
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
user.password # => 'something'
|
|
59
61
|
|
|
62
|
+
Now:
|
|
60
63
|
|
|
61
|
-
|
|
64
|
+
user.password = 'something'
|
|
65
|
+
user.password = nil
|
|
62
66
|
|
|
63
|
-
|
|
67
|
+
user.password # => nil
|
|
64
68
|
|
|
69
|
+
*Markus Doits*
|
|
65
70
|
|
|
66
|
-
|
|
71
|
+
* Fix delegation in `ActiveModel::Type::Registry#lookup` and `ActiveModel::Type.lookup`
|
|
67
72
|
|
|
68
|
-
|
|
73
|
+
Passing a last positional argument `{}` would be incorrectly considered as keyword argument.
|
|
69
74
|
|
|
75
|
+
*Benoit Daloze*
|
|
70
76
|
|
|
71
|
-
|
|
77
|
+
* Fix `to_json` after `changes_applied` for `ActiveModel::Dirty` object.
|
|
72
78
|
|
|
73
|
-
*
|
|
79
|
+
*Ryuta Kamizono*
|
|
74
80
|
|
|
75
81
|
|
|
76
|
-
## Rails 6.
|
|
82
|
+
## Rails 6.1.4.7 (March 08, 2022) ##
|
|
77
83
|
|
|
78
84
|
* No changes.
|
|
79
85
|
|
|
80
86
|
|
|
81
|
-
## Rails 6.
|
|
87
|
+
## Rails 6.1.4.6 (February 11, 2022) ##
|
|
82
88
|
|
|
83
89
|
* No changes.
|
|
84
90
|
|
|
85
91
|
|
|
86
|
-
## Rails 6.
|
|
92
|
+
## Rails 6.1.4.5 (February 11, 2022) ##
|
|
87
93
|
|
|
88
94
|
* No changes.
|
|
89
95
|
|
|
90
96
|
|
|
91
|
-
## Rails 6.
|
|
97
|
+
## Rails 6.1.4.4 (December 15, 2021) ##
|
|
92
98
|
|
|
93
99
|
* No changes.
|
|
94
100
|
|
|
95
101
|
|
|
96
|
-
## Rails 6.
|
|
102
|
+
## Rails 6.1.4.3 (December 14, 2021) ##
|
|
97
103
|
|
|
98
104
|
* No changes.
|
|
99
105
|
|
|
100
106
|
|
|
101
|
-
## Rails 6.
|
|
107
|
+
## Rails 6.1.4.2 (December 14, 2021) ##
|
|
102
108
|
|
|
103
109
|
* No changes.
|
|
104
110
|
|
|
105
111
|
|
|
106
|
-
## Rails 6.
|
|
112
|
+
## Rails 6.1.4.1 (August 19, 2021) ##
|
|
107
113
|
|
|
108
114
|
* No changes.
|
|
109
115
|
|
|
110
116
|
|
|
111
|
-
## Rails 6.
|
|
117
|
+
## Rails 6.1.4 (June 24, 2021) ##
|
|
112
118
|
|
|
113
|
-
*
|
|
119
|
+
* Fix `to_json` for `ActiveModel::Dirty` object.
|
|
114
120
|
|
|
121
|
+
Exclude +mutations_from_database+ attribute from json as it lead to recursion.
|
|
115
122
|
|
|
116
|
-
|
|
123
|
+
*Anil Maurya*
|
|
117
124
|
|
|
118
|
-
* No changes.
|
|
119
125
|
|
|
120
|
-
|
|
121
|
-
## Rails 6.0.1 (November 5, 2019) ##
|
|
126
|
+
## Rails 6.1.3.2 (May 05, 2021) ##
|
|
122
127
|
|
|
123
128
|
* No changes.
|
|
124
129
|
|
|
125
130
|
|
|
126
|
-
## Rails 6.
|
|
131
|
+
## Rails 6.1.3.1 (March 26, 2021) ##
|
|
127
132
|
|
|
128
133
|
* No changes.
|
|
129
134
|
|
|
130
135
|
|
|
131
|
-
## Rails 6.
|
|
136
|
+
## Rails 6.1.3 (February 17, 2021) ##
|
|
132
137
|
|
|
133
138
|
* No changes.
|
|
134
139
|
|
|
135
140
|
|
|
136
|
-
## Rails 6.
|
|
137
|
-
|
|
138
|
-
* Type cast falsy boolean symbols on boolean attribute as false.
|
|
139
|
-
|
|
140
|
-
Fixes #35676.
|
|
141
|
-
|
|
142
|
-
*Ryuta Kamizono*
|
|
143
|
-
|
|
144
|
-
* Change how validation error translation strings are fetched: The new behavior
|
|
145
|
-
will first try the more specific keys, including doing locale fallback, then try
|
|
146
|
-
the less specific ones.
|
|
147
|
-
|
|
148
|
-
For example, this is the order in which keys will now be tried for a `blank`
|
|
149
|
-
error on a `product`'s `title` attribute with current locale set to `en-US`:
|
|
150
|
-
|
|
151
|
-
en-US.activerecord.errors.models.product.attributes.title.blank
|
|
152
|
-
en-US.activerecord.errors.models.product.blank
|
|
153
|
-
en-US.activerecord.errors.messages.blank
|
|
154
|
-
|
|
155
|
-
en.activerecord.errors.models.product.attributes.title.blank
|
|
156
|
-
en.activerecord.errors.models.product.blank
|
|
157
|
-
en.activerecord.errors.messages.blank
|
|
158
|
-
|
|
159
|
-
en-US.errors.attributes.title.blank
|
|
160
|
-
en-US.errors.messages.blank
|
|
161
|
-
|
|
162
|
-
en.errors.attributes.title.blank
|
|
163
|
-
en.errors.messages.blank
|
|
164
|
-
|
|
165
|
-
*Hugo Vacher*
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
## Rails 6.0.0.beta3 (March 11, 2019) ##
|
|
141
|
+
## Rails 6.1.2.1 (February 10, 2021) ##
|
|
169
142
|
|
|
170
143
|
* No changes.
|
|
171
144
|
|
|
172
145
|
|
|
173
|
-
## Rails 6.
|
|
174
|
-
|
|
175
|
-
* Fix date value when casting a multiparameter date hash to not convert
|
|
176
|
-
from Gregorian date to Julian date.
|
|
177
|
-
|
|
178
|
-
Before:
|
|
179
|
-
|
|
180
|
-
Day.new({"day(1i)"=>"1", "day(2i)"=>"1", "day(3i)"=>"1"})
|
|
181
|
-
# => #<Day id: nil, day: "0001-01-03", created_at: nil, updated_at: nil>
|
|
182
|
-
|
|
183
|
-
After:
|
|
184
|
-
|
|
185
|
-
Day.new({"day(1i)"=>"1", "day(2i)"=>"1", "day(3i)"=>"1"})
|
|
186
|
-
# => #<Day id: nil, day: "0001-01-01", created_at: nil, updated_at: nil>
|
|
187
|
-
|
|
188
|
-
Fixes #28521.
|
|
189
|
-
|
|
190
|
-
*Sayan Chakraborty*
|
|
191
|
-
|
|
192
|
-
* Fix year value when casting a multiparameter time hash.
|
|
193
|
-
|
|
194
|
-
When assigning a hash to a time attribute that's missing a year component
|
|
195
|
-
(e.g. a `time_select` with `:ignore_date` set to `true`) then the year
|
|
196
|
-
defaults to 1970 instead of the expected 2000. This results in the attribute
|
|
197
|
-
changing as a result of the save.
|
|
146
|
+
## Rails 6.1.2 (February 09, 2021) ##
|
|
198
147
|
|
|
199
|
-
|
|
200
|
-
```
|
|
201
|
-
event = Event.new(start_time: { 4 => 20, 5 => 30 })
|
|
202
|
-
event.start_time # => 1970-01-01 20:30:00 UTC
|
|
203
|
-
event.save
|
|
204
|
-
event.reload
|
|
205
|
-
event.start_time # => 2000-01-01 20:30:00 UTC
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
After:
|
|
209
|
-
```
|
|
210
|
-
event = Event.new(start_time: { 4 => 20, 5 => 30 })
|
|
211
|
-
event.start_time # => 2000-01-01 20:30:00 UTC
|
|
212
|
-
event.save
|
|
213
|
-
event.reload
|
|
214
|
-
event.start_time # => 2000-01-01 20:30:00 UTC
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
*Andrew White*
|
|
148
|
+
* No changes.
|
|
218
149
|
|
|
219
150
|
|
|
220
|
-
## Rails 6.
|
|
151
|
+
## Rails 6.1.1 (January 07, 2021) ##
|
|
221
152
|
|
|
222
|
-
*
|
|
223
|
-
in some cases.
|
|
153
|
+
* No changes.
|
|
224
154
|
|
|
225
|
-
This is in line with examples in Rails docs and puts the code in line with the intention -
|
|
226
|
-
the potential use of strings or symbols.
|
|
227
155
|
|
|
228
|
-
|
|
156
|
+
## Rails 6.1.0 (December 09, 2020) ##
|
|
229
157
|
|
|
230
|
-
|
|
158
|
+
* Pass in `base` instead of `base_class` to Error.human_attribute_name
|
|
231
159
|
|
|
232
|
-
|
|
160
|
+
This is useful in cases where the `human_attribute_name` method depends
|
|
161
|
+
on other attributes' values of the class under validation to derive what the
|
|
162
|
+
attribute name should be.
|
|
233
163
|
|
|
234
|
-
*
|
|
164
|
+
*Filipe Sabella*
|
|
235
165
|
|
|
236
|
-
*
|
|
237
|
-
by casting to `BigDecimal` on both ends of the validation.
|
|
166
|
+
* Deprecate marshalling load from legacy attributes format.
|
|
238
167
|
|
|
239
|
-
*
|
|
168
|
+
*Ryuta Kamizono*
|
|
240
169
|
|
|
241
|
-
*
|
|
170
|
+
* `*_previously_changed?` accepts `:from` and `:to` keyword arguments like `*_changed?`.
|
|
242
171
|
|
|
243
|
-
|
|
172
|
+
topic.update!(status: :archived)
|
|
173
|
+
topic.status_previously_changed?(from: "active", to: "archived")
|
|
174
|
+
# => true
|
|
244
175
|
|
|
245
|
-
*
|
|
176
|
+
*George Claghorn*
|
|
246
177
|
|
|
247
|
-
|
|
178
|
+
* Raise FrozenError when trying to write attributes that aren't backed by the database on an object that is frozen:
|
|
248
179
|
|
|
249
|
-
|
|
180
|
+
class Animal
|
|
181
|
+
include ActiveModel::Attributes
|
|
182
|
+
attribute :age
|
|
183
|
+
end
|
|
250
184
|
|
|
251
|
-
|
|
185
|
+
animal = Animal.new
|
|
186
|
+
animal.freeze
|
|
187
|
+
animal.age = 25 # => FrozenError, "can't modify a frozen Animal"
|
|
252
188
|
|
|
253
|
-
|
|
254
|
-
```
|
|
255
|
-
contact = Contact.new(created_at: Time.utc(2006, 8, 1))
|
|
256
|
-
contact.as_json["created_at"] # => 2006-08-01 00:00:00 UTC
|
|
257
|
-
```
|
|
189
|
+
*Josh Brody*
|
|
258
190
|
|
|
259
|
-
|
|
260
|
-
```
|
|
261
|
-
contact = Contact.new(created_at: Time.utc(2006, 8, 1))
|
|
262
|
-
contact.as_json["created_at"] # => "2006-08-01T00:00:00.000Z"
|
|
263
|
-
```
|
|
191
|
+
* Add `*_previously_was` attribute methods when dirty tracking. Example:
|
|
264
192
|
|
|
265
|
-
|
|
193
|
+
pirate.update(catchphrase: "Ahoy!")
|
|
194
|
+
pirate.previous_changes["catchphrase"] # => ["Thar She Blows!", "Ahoy!"]
|
|
195
|
+
pirate.catchphrase_previously_was # => "Thar She Blows!"
|
|
266
196
|
|
|
267
|
-
*
|
|
268
|
-
still defaults to an attribute named 'password', causing no breaking
|
|
269
|
-
change. There is a new method `#authenticate_XXX` where XXX is the
|
|
270
|
-
configured attribute name, making the existing `#authenticate` now an
|
|
271
|
-
alias for this when the attribute is the default 'password'.
|
|
197
|
+
*DHH*
|
|
272
198
|
|
|
273
|
-
|
|
199
|
+
* Encapsulate each validation error as an Error object.
|
|
274
200
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
end
|
|
201
|
+
The `ActiveModel`’s `errors` collection is now an array of these Error
|
|
202
|
+
objects, instead of messages/details hash.
|
|
278
203
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
user.authenticate_recovery_password('42password') # => user
|
|
204
|
+
For each of these `Error` object, its `message` and `full_message` methods
|
|
205
|
+
are for generating error messages. Its `details` method would return error’s
|
|
206
|
+
extra parameters, found in the original `details` hash.
|
|
283
207
|
|
|
284
|
-
|
|
208
|
+
The change tries its best at maintaining backward compatibility, however
|
|
209
|
+
some edge cases won’t be covered, like `errors#first` will return `ActiveModel::Error` and manipulating
|
|
210
|
+
`errors.messages` and `errors.details` hashes directly will have no effect. Moving forward,
|
|
211
|
+
please convert those direct manipulations to use provided API methods instead.
|
|
212
|
+
Please note that `errors#add` now accepts `options` as keyword arguments instead of `Hash` which
|
|
213
|
+
introduced a change in Ruby 3 to [keyword arguments][kwargs-ann].
|
|
285
214
|
|
|
286
|
-
|
|
287
|
-
the `full_message` error format can be overridden at the attribute or model
|
|
288
|
-
level in the locale files. This is `false` by default.
|
|
215
|
+
[kwargs-ann]: https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
|
|
289
216
|
|
|
290
|
-
|
|
217
|
+
The list of deprecated methods and their planned future behavioral changes at the next major release are:
|
|
291
218
|
|
|
292
|
-
*
|
|
219
|
+
* `errors#slice!` will be removed.
|
|
220
|
+
* `errors#each` with the `key, value` two-arguments block will stop working, while the `error` single-argument block would return `Error` object.
|
|
221
|
+
* `errors#values` will be removed.
|
|
222
|
+
* `errors#keys` will be removed.
|
|
223
|
+
* `errors#to_xml` will be removed.
|
|
224
|
+
* `errors#to_h` will be removed, and can be replaced with `errors#to_hash`.
|
|
225
|
+
* Manipulating `errors` itself as a hash will have no effect (e.g. `errors[:foo] = 'bar'`).
|
|
226
|
+
* Manipulating the hash returned by `errors#messages` (e.g. `errors.messages[:foo] = 'bar'`) will have no effect.
|
|
227
|
+
* Manipulating the hash returned by `errors#details` (e.g. `errors.details[:foo].clear`) will have no effect.
|
|
293
228
|
|
|
294
|
-
*
|
|
229
|
+
*lulalala*
|
|
295
230
|
|
|
296
231
|
|
|
297
|
-
Please check [
|
|
232
|
+
Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activemodel/CHANGELOG.md) for previous changes.
|
data/MIT-LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (c) 2004-
|
|
1
|
+
Copyright (c) 2004-2022 David Heinemeier Hansson
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
4
|
a copy of this software and associated documentation files (the
|
|
@@ -18,4 +18,3 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
20
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
-
|
data/README.rdoc
CHANGED
|
@@ -200,7 +200,7 @@ behavior out of the box:
|
|
|
200
200
|
attr_accessor :first_name, :last_name
|
|
201
201
|
|
|
202
202
|
validates_each :first_name, :last_name do |record, attr, value|
|
|
203
|
-
record.errors.add attr,
|
|
203
|
+
record.errors.add attr, "starts with z." if value.start_with?("z")
|
|
204
204
|
end
|
|
205
205
|
end
|
|
206
206
|
|
|
@@ -5,16 +5,16 @@ require "active_support/core_ext/object/duplicable"
|
|
|
5
5
|
module ActiveModel
|
|
6
6
|
class Attribute # :nodoc:
|
|
7
7
|
class << self
|
|
8
|
-
def from_database(name,
|
|
9
|
-
FromDatabase.new(name,
|
|
8
|
+
def from_database(name, value_before_type_cast, type, value = nil)
|
|
9
|
+
FromDatabase.new(name, value_before_type_cast, type, nil, value)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def from_user(name,
|
|
13
|
-
FromUser.new(name,
|
|
12
|
+
def from_user(name, value_before_type_cast, type, original_attribute = nil)
|
|
13
|
+
FromUser.new(name, value_before_type_cast, type, original_attribute)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def with_cast_value(name,
|
|
17
|
-
WithCastValue.new(name,
|
|
16
|
+
def with_cast_value(name, value_before_type_cast, type)
|
|
17
|
+
WithCastValue.new(name, value_before_type_cast, type)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def null(name)
|
|
@@ -30,11 +30,12 @@ module ActiveModel
|
|
|
30
30
|
|
|
31
31
|
# This method should not be called directly.
|
|
32
32
|
# Use #from_database or #from_user
|
|
33
|
-
def initialize(name, value_before_type_cast, type, original_attribute = nil)
|
|
33
|
+
def initialize(name, value_before_type_cast, type, original_attribute = nil, value = nil)
|
|
34
34
|
@name = name
|
|
35
35
|
@value_before_type_cast = value_before_type_cast
|
|
36
36
|
@type = type
|
|
37
37
|
@original_attribute = original_attribute
|
|
38
|
+
@value = value unless value.nil?
|
|
38
39
|
end
|
|
39
40
|
|
|
40
41
|
def value
|
|
@@ -132,14 +133,13 @@ module ActiveModel
|
|
|
132
133
|
coder["value"] = value if defined?(@value)
|
|
133
134
|
end
|
|
134
135
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
_original_value_for_database
|
|
141
|
-
end
|
|
136
|
+
def original_value_for_database
|
|
137
|
+
if assigned?
|
|
138
|
+
original_attribute.original_value_for_database
|
|
139
|
+
else
|
|
140
|
+
_original_value_for_database
|
|
142
141
|
end
|
|
142
|
+
end
|
|
143
143
|
|
|
144
144
|
private
|
|
145
145
|
attr_reader :original_attribute
|
|
@@ -164,9 +164,10 @@ module ActiveModel
|
|
|
164
164
|
type.deserialize(value)
|
|
165
165
|
end
|
|
166
166
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
private
|
|
168
|
+
def _original_value_for_database
|
|
169
|
+
value_before_type_cast
|
|
170
|
+
end
|
|
170
171
|
end
|
|
171
172
|
|
|
172
173
|
class FromUser < Attribute # :nodoc:
|
|
@@ -26,13 +26,12 @@ module ActiveModel
|
|
|
26
26
|
# cat.name # => 'Gorby'
|
|
27
27
|
# cat.status # => 'sleeping'
|
|
28
28
|
def assign_attributes(new_attributes)
|
|
29
|
-
|
|
29
|
+
unless new_attributes.respond_to?(:each_pair)
|
|
30
30
|
raise ArgumentError, "When assigning attributes, you must pass a hash as an argument, #{new_attributes.class} passed."
|
|
31
31
|
end
|
|
32
32
|
return if new_attributes.empty?
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
_assign_attributes(sanitize_for_mass_assignment(attributes))
|
|
34
|
+
_assign_attributes(sanitize_for_mass_assignment(new_attributes))
|
|
36
35
|
end
|
|
37
36
|
|
|
38
37
|
alias attributes= assign_attributes
|
|
@@ -49,7 +48,7 @@ module ActiveModel
|
|
|
49
48
|
if respond_to?(setter)
|
|
50
49
|
public_send(setter, v)
|
|
51
50
|
else
|
|
52
|
-
raise UnknownAttributeError.new(self, k)
|
|
51
|
+
raise UnknownAttributeError.new(self, k.to_s)
|
|
53
52
|
end
|
|
54
53
|
end
|
|
55
54
|
end
|