activemodel 6.0.5.1 → 6.1.7.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 +95 -160
- 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 +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcf46c9630a1432b746e09ee7cac5284f26438250df94958968d989ea91409e5
|
4
|
+
data.tar.gz: 3845512ed933040899396e26931811c96f391012a2643d76dea265095a3e93e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d93de2900e47e8d43dd9f0350f16da5f4d77058369b10946029c3d3a1844038ec151f491fff25613473bf2dd06edc83fc4bee05dfef3e3dffab45222eba2a8f5
|
7
|
+
data.tar.gz: ab44f9409e4bfcec47891b6df004bbff453440c9c3fdc6b9760f4c5cafbf46d195a1d2a23a6d581dcacb2db247d038280c72fa909fd497149990be1aeef34f4f
|
data/CHANGELOG.md
CHANGED
@@ -1,287 +1,222 @@
|
|
1
|
-
## Rails 6.
|
1
|
+
## Rails 6.1.7.4 (June 26, 2023) ##
|
2
2
|
|
3
3
|
* No changes.
|
4
4
|
|
5
5
|
|
6
|
-
## Rails 6.
|
6
|
+
## Rails 6.1.7.3 (March 13, 2023) ##
|
7
7
|
|
8
8
|
* No changes.
|
9
9
|
|
10
10
|
|
11
|
-
## Rails 6.
|
11
|
+
## Rails 6.1.7.2 (January 24, 2023) ##
|
12
12
|
|
13
13
|
* No changes.
|
14
14
|
|
15
15
|
|
16
|
-
## Rails 6.
|
16
|
+
## Rails 6.1.7.1 (January 17, 2023) ##
|
17
17
|
|
18
18
|
* No changes.
|
19
19
|
|
20
20
|
|
21
|
-
## Rails 6.
|
21
|
+
## Rails 6.1.7 (September 09, 2022) ##
|
22
22
|
|
23
23
|
* No changes.
|
24
24
|
|
25
25
|
|
26
|
-
## Rails 6.
|
26
|
+
## Rails 6.1.6.1 (July 12, 2022) ##
|
27
27
|
|
28
28
|
* No changes.
|
29
29
|
|
30
30
|
|
31
|
-
## Rails 6.
|
31
|
+
## Rails 6.1.6 (May 09, 2022) ##
|
32
32
|
|
33
33
|
* No changes.
|
34
34
|
|
35
35
|
|
36
|
-
## Rails 6.
|
36
|
+
## Rails 6.1.5.1 (April 26, 2022) ##
|
37
37
|
|
38
38
|
* No changes.
|
39
39
|
|
40
40
|
|
41
|
-
## Rails 6.
|
41
|
+
## Rails 6.1.5 (March 09, 2022) ##
|
42
42
|
|
43
|
-
*
|
43
|
+
* Clear secure password cache if password is set to `nil`
|
44
44
|
|
45
|
+
Before:
|
45
46
|
|
46
|
-
|
47
|
+
user.password = 'something'
|
48
|
+
user.password = nil
|
47
49
|
|
48
|
-
|
50
|
+
user.password # => 'something'
|
49
51
|
|
52
|
+
Now:
|
50
53
|
|
51
|
-
|
54
|
+
user.password = 'something'
|
55
|
+
user.password = nil
|
52
56
|
|
53
|
-
|
57
|
+
user.password # => nil
|
54
58
|
|
59
|
+
*Markus Doits*
|
55
60
|
|
56
|
-
|
61
|
+
* Fix delegation in `ActiveModel::Type::Registry#lookup` and `ActiveModel::Type.lookup`
|
57
62
|
|
58
|
-
|
63
|
+
Passing a last positional argument `{}` would be incorrectly considered as keyword argument.
|
59
64
|
|
65
|
+
*Benoit Daloze*
|
60
66
|
|
61
|
-
|
67
|
+
* Fix `to_json` after `changes_applied` for `ActiveModel::Dirty` object.
|
62
68
|
|
63
|
-
*
|
69
|
+
*Ryuta Kamizono*
|
64
70
|
|
65
71
|
|
66
|
-
## Rails 6.
|
72
|
+
## Rails 6.1.4.7 (March 08, 2022) ##
|
67
73
|
|
68
74
|
* No changes.
|
69
75
|
|
70
76
|
|
71
|
-
## Rails 6.
|
77
|
+
## Rails 6.1.4.6 (February 11, 2022) ##
|
72
78
|
|
73
79
|
* No changes.
|
74
80
|
|
75
81
|
|
76
|
-
## Rails 6.
|
82
|
+
## Rails 6.1.4.5 (February 11, 2022) ##
|
77
83
|
|
78
84
|
* No changes.
|
79
85
|
|
80
86
|
|
81
|
-
## Rails 6.
|
87
|
+
## Rails 6.1.4.4 (December 15, 2021) ##
|
82
88
|
|
83
89
|
* No changes.
|
84
90
|
|
85
91
|
|
86
|
-
## Rails 6.
|
92
|
+
## Rails 6.1.4.3 (December 14, 2021) ##
|
87
93
|
|
88
94
|
* No changes.
|
89
95
|
|
90
96
|
|
91
|
-
## Rails 6.
|
97
|
+
## Rails 6.1.4.2 (December 14, 2021) ##
|
92
98
|
|
93
99
|
* No changes.
|
94
100
|
|
95
101
|
|
96
|
-
## Rails 6.
|
102
|
+
## Rails 6.1.4.1 (August 19, 2021) ##
|
97
103
|
|
98
104
|
* No changes.
|
99
105
|
|
100
106
|
|
101
|
-
## Rails 6.
|
107
|
+
## Rails 6.1.4 (June 24, 2021) ##
|
102
108
|
|
103
|
-
*
|
109
|
+
* Fix `to_json` for `ActiveModel::Dirty` object.
|
104
110
|
|
111
|
+
Exclude +mutations_from_database+ attribute from json as it lead to recursion.
|
105
112
|
|
106
|
-
|
113
|
+
*Anil Maurya*
|
107
114
|
|
108
|
-
* No changes.
|
109
115
|
|
110
|
-
|
111
|
-
## Rails 6.0.1 (November 5, 2019) ##
|
116
|
+
## Rails 6.1.3.2 (May 05, 2021) ##
|
112
117
|
|
113
118
|
* No changes.
|
114
119
|
|
115
120
|
|
116
|
-
## Rails 6.
|
121
|
+
## Rails 6.1.3.1 (March 26, 2021) ##
|
117
122
|
|
118
123
|
* No changes.
|
119
124
|
|
120
125
|
|
121
|
-
## Rails 6.
|
126
|
+
## Rails 6.1.3 (February 17, 2021) ##
|
122
127
|
|
123
128
|
* No changes.
|
124
129
|
|
125
130
|
|
126
|
-
## Rails 6.
|
127
|
-
|
128
|
-
* Type cast falsy boolean symbols on boolean attribute as false.
|
129
|
-
|
130
|
-
Fixes #35676.
|
131
|
-
|
132
|
-
*Ryuta Kamizono*
|
133
|
-
|
134
|
-
* Change how validation error translation strings are fetched: The new behavior
|
135
|
-
will first try the more specific keys, including doing locale fallback, then try
|
136
|
-
the less specific ones.
|
137
|
-
|
138
|
-
For example, this is the order in which keys will now be tried for a `blank`
|
139
|
-
error on a `product`'s `title` attribute with current locale set to `en-US`:
|
140
|
-
|
141
|
-
en-US.activerecord.errors.models.product.attributes.title.blank
|
142
|
-
en-US.activerecord.errors.models.product.blank
|
143
|
-
en-US.activerecord.errors.messages.blank
|
144
|
-
|
145
|
-
en.activerecord.errors.models.product.attributes.title.blank
|
146
|
-
en.activerecord.errors.models.product.blank
|
147
|
-
en.activerecord.errors.messages.blank
|
148
|
-
|
149
|
-
en-US.errors.attributes.title.blank
|
150
|
-
en-US.errors.messages.blank
|
151
|
-
|
152
|
-
en.errors.attributes.title.blank
|
153
|
-
en.errors.messages.blank
|
154
|
-
|
155
|
-
*Hugo Vacher*
|
156
|
-
|
157
|
-
|
158
|
-
## Rails 6.0.0.beta3 (March 11, 2019) ##
|
131
|
+
## Rails 6.1.2.1 (February 10, 2021) ##
|
159
132
|
|
160
133
|
* No changes.
|
161
134
|
|
162
135
|
|
163
|
-
## Rails 6.
|
164
|
-
|
165
|
-
* Fix date value when casting a multiparameter date hash to not convert
|
166
|
-
from Gregorian date to Julian date.
|
167
|
-
|
168
|
-
Before:
|
169
|
-
|
170
|
-
Day.new({"day(1i)"=>"1", "day(2i)"=>"1", "day(3i)"=>"1"})
|
171
|
-
# => #<Day id: nil, day: "0001-01-03", created_at: nil, updated_at: nil>
|
172
|
-
|
173
|
-
After:
|
174
|
-
|
175
|
-
Day.new({"day(1i)"=>"1", "day(2i)"=>"1", "day(3i)"=>"1"})
|
176
|
-
# => #<Day id: nil, day: "0001-01-01", created_at: nil, updated_at: nil>
|
177
|
-
|
178
|
-
Fixes #28521.
|
179
|
-
|
180
|
-
*Sayan Chakraborty*
|
181
|
-
|
182
|
-
* Fix year value when casting a multiparameter time hash.
|
183
|
-
|
184
|
-
When assigning a hash to a time attribute that's missing a year component
|
185
|
-
(e.g. a `time_select` with `:ignore_date` set to `true`) then the year
|
186
|
-
defaults to 1970 instead of the expected 2000. This results in the attribute
|
187
|
-
changing as a result of the save.
|
136
|
+
## Rails 6.1.2 (February 09, 2021) ##
|
188
137
|
|
189
|
-
|
190
|
-
```
|
191
|
-
event = Event.new(start_time: { 4 => 20, 5 => 30 })
|
192
|
-
event.start_time # => 1970-01-01 20:30:00 UTC
|
193
|
-
event.save
|
194
|
-
event.reload
|
195
|
-
event.start_time # => 2000-01-01 20:30:00 UTC
|
196
|
-
```
|
197
|
-
|
198
|
-
After:
|
199
|
-
```
|
200
|
-
event = Event.new(start_time: { 4 => 20, 5 => 30 })
|
201
|
-
event.start_time # => 2000-01-01 20:30:00 UTC
|
202
|
-
event.save
|
203
|
-
event.reload
|
204
|
-
event.start_time # => 2000-01-01 20:30:00 UTC
|
205
|
-
```
|
206
|
-
|
207
|
-
*Andrew White*
|
138
|
+
* No changes.
|
208
139
|
|
209
140
|
|
210
|
-
## Rails 6.
|
141
|
+
## Rails 6.1.1 (January 07, 2021) ##
|
211
142
|
|
212
|
-
*
|
213
|
-
in some cases.
|
143
|
+
* No changes.
|
214
144
|
|
215
|
-
This is in line with examples in Rails docs and puts the code in line with the intention -
|
216
|
-
the potential use of strings or symbols.
|
217
145
|
|
218
|
-
|
146
|
+
## Rails 6.1.0 (December 09, 2020) ##
|
219
147
|
|
220
|
-
|
148
|
+
* Pass in `base` instead of `base_class` to Error.human_attribute_name
|
221
149
|
|
222
|
-
|
150
|
+
This is useful in cases where the `human_attribute_name` method depends
|
151
|
+
on other attributes' values of the class under validation to derive what the
|
152
|
+
attribute name should be.
|
223
153
|
|
224
|
-
*
|
154
|
+
*Filipe Sabella*
|
225
155
|
|
226
|
-
*
|
227
|
-
by casting to `BigDecimal` on both ends of the validation.
|
156
|
+
* Deprecate marshalling load from legacy attributes format.
|
228
157
|
|
229
|
-
*
|
158
|
+
*Ryuta Kamizono*
|
230
159
|
|
231
|
-
*
|
160
|
+
* `*_previously_changed?` accepts `:from` and `:to` keyword arguments like `*_changed?`.
|
232
161
|
|
233
|
-
|
162
|
+
topic.update!(status: :archived)
|
163
|
+
topic.status_previously_changed?(from: "active", to: "archived")
|
164
|
+
# => true
|
234
165
|
|
235
|
-
*
|
166
|
+
*George Claghorn*
|
236
167
|
|
237
|
-
|
168
|
+
* Raise FrozenError when trying to write attributes that aren't backed by the database on an object that is frozen:
|
238
169
|
|
239
|
-
|
170
|
+
class Animal
|
171
|
+
include ActiveModel::Attributes
|
172
|
+
attribute :age
|
173
|
+
end
|
240
174
|
|
241
|
-
|
175
|
+
animal = Animal.new
|
176
|
+
animal.freeze
|
177
|
+
animal.age = 25 # => FrozenError, "can't modify a frozen Animal"
|
242
178
|
|
243
|
-
|
244
|
-
```
|
245
|
-
contact = Contact.new(created_at: Time.utc(2006, 8, 1))
|
246
|
-
contact.as_json["created_at"] # => 2006-08-01 00:00:00 UTC
|
247
|
-
```
|
179
|
+
*Josh Brody*
|
248
180
|
|
249
|
-
|
250
|
-
```
|
251
|
-
contact = Contact.new(created_at: Time.utc(2006, 8, 1))
|
252
|
-
contact.as_json["created_at"] # => "2006-08-01T00:00:00.000Z"
|
253
|
-
```
|
181
|
+
* Add `*_previously_was` attribute methods when dirty tracking. Example:
|
254
182
|
|
255
|
-
|
183
|
+
pirate.update(catchphrase: "Ahoy!")
|
184
|
+
pirate.previous_changes["catchphrase"] # => ["Thar She Blows!", "Ahoy!"]
|
185
|
+
pirate.catchphrase_previously_was # => "Thar She Blows!"
|
256
186
|
|
257
|
-
*
|
258
|
-
still defaults to an attribute named 'password', causing no breaking
|
259
|
-
change. There is a new method `#authenticate_XXX` where XXX is the
|
260
|
-
configured attribute name, making the existing `#authenticate` now an
|
261
|
-
alias for this when the attribute is the default 'password'.
|
187
|
+
*DHH*
|
262
188
|
|
263
|
-
|
189
|
+
* Encapsulate each validation error as an Error object.
|
264
190
|
|
265
|
-
|
266
|
-
|
267
|
-
end
|
191
|
+
The `ActiveModel`’s `errors` collection is now an array of these Error
|
192
|
+
objects, instead of messages/details hash.
|
268
193
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
user.authenticate_recovery_password('42password') # => user
|
194
|
+
For each of these `Error` object, its `message` and `full_message` methods
|
195
|
+
are for generating error messages. Its `details` method would return error’s
|
196
|
+
extra parameters, found in the original `details` hash.
|
273
197
|
|
274
|
-
|
198
|
+
The change tries its best at maintaining backward compatibility, however
|
199
|
+
some edge cases won’t be covered, like `errors#first` will return `ActiveModel::Error` and manipulating
|
200
|
+
`errors.messages` and `errors.details` hashes directly will have no effect. Moving forward,
|
201
|
+
please convert those direct manipulations to use provided API methods instead.
|
202
|
+
Please note that `errors#add` now accepts `options` as keyword arguments instead of `Hash` which
|
203
|
+
introduced a change in Ruby 3 to [keyword arguments][kwargs-ann].
|
275
204
|
|
276
|
-
|
277
|
-
the `full_message` error format can be overridden at the attribute or model
|
278
|
-
level in the locale files. This is `false` by default.
|
205
|
+
[kwargs-ann]: https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
|
279
206
|
|
280
|
-
|
207
|
+
The list of deprecated methods and their planned future behavioral changes at the next major release are:
|
281
208
|
|
282
|
-
*
|
209
|
+
* `errors#slice!` will be removed.
|
210
|
+
* `errors#each` with the `key, value` two-arguments block will stop working, while the `error` single-argument block would return `Error` object.
|
211
|
+
* `errors#values` will be removed.
|
212
|
+
* `errors#keys` will be removed.
|
213
|
+
* `errors#to_xml` will be removed.
|
214
|
+
* `errors#to_h` will be removed, and can be replaced with `errors#to_hash`.
|
215
|
+
* Manipulating `errors` itself as a hash will have no effect (e.g. `errors[:foo] = 'bar'`).
|
216
|
+
* Manipulating the hash returned by `errors#messages` (e.g. `errors.messages[:foo] = 'bar'`) will have no effect.
|
217
|
+
* Manipulating the hash returned by `errors#details` (e.g. `errors.details[:foo].clear`) will have no effect.
|
283
218
|
|
284
|
-
*
|
219
|
+
*lulalala*
|
285
220
|
|
286
221
|
|
287
|
-
Please check [
|
222
|
+
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
|