activemodel 7.0.0.alpha2 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +83 -1
- data/lib/active_model/attribute_methods.rb +3 -66
- data/lib/active_model/attribute_set/builder.rb +1 -10
- data/lib/active_model/errors.rb +24 -238
- data/lib/active_model/gem_version.rb +1 -1
- data/lib/active_model/secure_password.rb +2 -1
- data/lib/active_model/type/date.rb +1 -1
- data/lib/active_model/type/helpers/time_value.rb +1 -1
- data/lib/active_model/validations/numericality.rb +1 -1
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9db6d3afd6b2229e9937481ca1b015819f8d55e0368e1a834177b1f60dd09d8
|
4
|
+
data.tar.gz: 3aef39f0ea6189a8fbe7dbb8500deead474df01cbbce41b9eea5629e31cd4e55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f6a49652ed96538b7cea9726a40be7c557b2d4ae95bc87e69b97ab44c057c77482ef0ceaac4f20726506798136825289ffa765a6b89254a8a91f7a8050702b3
|
7
|
+
data.tar.gz: c9ea97c715715e8e88e791adf11eadf1588309bbbf1de30be56a81e2991af510c9a30cae24a170ae7f015eda20c5a5617b9ab92a216eabd331deeed39fef7f4e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,85 @@
|
|
1
|
+
## Rails 7.0.0 (December 15, 2021) ##
|
2
|
+
|
3
|
+
* No changes.
|
4
|
+
|
5
|
+
|
6
|
+
## Rails 7.0.0.rc3 (December 14, 2021) ##
|
7
|
+
|
8
|
+
* No changes.
|
9
|
+
|
10
|
+
|
11
|
+
## Rails 7.0.0.rc2 (December 14, 2021) ##
|
12
|
+
|
13
|
+
* No changes.
|
14
|
+
|
15
|
+
## Rails 7.0.0.rc1 (December 06, 2021) ##
|
16
|
+
|
17
|
+
* Remove support to Marshal load Rails 5.x `ActiveModel::AttributeSet` format.
|
18
|
+
|
19
|
+
*Rafael Mendonça França*
|
20
|
+
|
21
|
+
* Remove support to Marshal and YAML load Rails 5.x error format.
|
22
|
+
|
23
|
+
*Rafael Mendonça França*
|
24
|
+
|
25
|
+
* Remove deprecated support to use `[]=` in `ActiveModel::Errors#messages`.
|
26
|
+
|
27
|
+
*Rafael Mendonça França*
|
28
|
+
|
29
|
+
* Remove deprecated support to `delete` errors from `ActiveModel::Errors#messages`.
|
30
|
+
|
31
|
+
*Rafael Mendonça França*
|
32
|
+
|
33
|
+
* Remove deprecated support to `clear` errors from `ActiveModel::Errors#messages`.
|
34
|
+
|
35
|
+
*Rafael Mendonça França*
|
36
|
+
|
37
|
+
* Remove deprecated support concat errors to `ActiveModel::Errors#messages`.
|
38
|
+
|
39
|
+
*Rafael Mendonça França*
|
40
|
+
|
41
|
+
* Remove deprecated `ActiveModel::Errors#to_xml`.
|
42
|
+
|
43
|
+
*Rafael Mendonça França*
|
44
|
+
|
45
|
+
* Remove deprecated `ActiveModel::Errors#keys`.
|
46
|
+
|
47
|
+
*Rafael Mendonça França*
|
48
|
+
|
49
|
+
* Remove deprecated `ActiveModel::Errors#values`.
|
50
|
+
|
51
|
+
*Rafael Mendonça França*
|
52
|
+
|
53
|
+
* Remove deprecated `ActiveModel::Errors#slice!`.
|
54
|
+
|
55
|
+
*Rafael Mendonça França*
|
56
|
+
|
57
|
+
* Remove deprecated `ActiveModel::Errors#to_h`.
|
58
|
+
|
59
|
+
*Rafael Mendonça França*
|
60
|
+
|
61
|
+
* Remove deprecated enumeration of `ActiveModel::Errors` instances as a Hash.
|
62
|
+
|
63
|
+
*Rafael Mendonça França*
|
64
|
+
|
65
|
+
* Clear secure password cache if password is set to `nil`
|
66
|
+
|
67
|
+
Before:
|
68
|
+
|
69
|
+
user.password = 'something'
|
70
|
+
user.password = nil
|
71
|
+
|
72
|
+
user.password # => 'something'
|
73
|
+
|
74
|
+
Now:
|
75
|
+
|
76
|
+
user.password = 'something'
|
77
|
+
user.password = nil
|
78
|
+
|
79
|
+
user.password # => nil
|
80
|
+
|
81
|
+
*Markus Doits*
|
82
|
+
|
1
83
|
## Rails 7.0.0.alpha2 (September 15, 2021) ##
|
2
84
|
|
3
85
|
* No changes.
|
@@ -14,7 +96,7 @@
|
|
14
96
|
|
15
97
|
* Fix dirty check for Float::NaN and BigDecimal::NaN.
|
16
98
|
|
17
|
-
Float::NaN and BigDecimal::NaN in Ruby are [special values](https://bugs.ruby-lang.org/issues/1720)
|
99
|
+
Float::NaN and BigDecimal::NaN in Ruby are [special values](https://bugs.ruby-lang.org/issues/1720)
|
18
100
|
and can't be compared with `==`.
|
19
101
|
|
20
102
|
*Marcelo Lauxen*
|
@@ -208,7 +208,7 @@ module ActiveModel
|
|
208
208
|
# person.nickname_short? # => true
|
209
209
|
def alias_attribute(new_name, old_name)
|
210
210
|
self.attribute_aliases = attribute_aliases.merge(new_name.to_s => old_name.to_s)
|
211
|
-
CodeGenerator.batch(self, __FILE__, __LINE__) do |code_generator|
|
211
|
+
ActiveSupport::CodeGenerator.batch(self, __FILE__, __LINE__) do |code_generator|
|
212
212
|
attribute_method_matchers.each do |matcher|
|
213
213
|
method_name = matcher.method_name(new_name).to_s
|
214
214
|
target_name = matcher.method_name(old_name).to_s
|
@@ -274,7 +274,7 @@ module ActiveModel
|
|
274
274
|
# end
|
275
275
|
# end
|
276
276
|
def define_attribute_methods(*attr_names)
|
277
|
-
CodeGenerator.batch(generated_attribute_methods, __FILE__, __LINE__) do |owner|
|
277
|
+
ActiveSupport::CodeGenerator.batch(generated_attribute_methods, __FILE__, __LINE__) do |owner|
|
278
278
|
attr_names.flatten.each { |attr_name| define_attribute_method(attr_name, _owner: owner) }
|
279
279
|
end
|
280
280
|
end
|
@@ -309,7 +309,7 @@ module ActiveModel
|
|
309
309
|
# person.name # => "Bob"
|
310
310
|
# person.name_short? # => true
|
311
311
|
def define_attribute_method(attr_name, _owner: generated_attribute_methods)
|
312
|
-
CodeGenerator.batch(_owner, __FILE__, __LINE__) do |owner|
|
312
|
+
ActiveSupport::CodeGenerator.batch(_owner, __FILE__, __LINE__) do |owner|
|
313
313
|
attribute_method_matchers.each do |matcher|
|
314
314
|
method_name = matcher.method_name(attr_name)
|
315
315
|
|
@@ -358,69 +358,6 @@ module ActiveModel
|
|
358
358
|
end
|
359
359
|
|
360
360
|
private
|
361
|
-
class CodeGenerator # :nodoc:
|
362
|
-
class MethodSet
|
363
|
-
METHOD_CACHES = Hash.new { |h, k| h[k] = Module.new }
|
364
|
-
|
365
|
-
def initialize(namespace)
|
366
|
-
@cache = METHOD_CACHES[namespace]
|
367
|
-
@sources = []
|
368
|
-
@methods = {}
|
369
|
-
end
|
370
|
-
|
371
|
-
def define_cached_method(name, as: name)
|
372
|
-
name = name.to_sym
|
373
|
-
as = as.to_sym
|
374
|
-
@methods.fetch(name) do
|
375
|
-
unless @cache.method_defined?(as)
|
376
|
-
yield @sources
|
377
|
-
end
|
378
|
-
@methods[name] = as
|
379
|
-
end
|
380
|
-
end
|
381
|
-
|
382
|
-
def apply(owner, path, line)
|
383
|
-
unless @sources.empty?
|
384
|
-
@cache.module_eval("# frozen_string_literal: true\n" + @sources.join(";"), path, line)
|
385
|
-
end
|
386
|
-
@methods.each do |name, as|
|
387
|
-
owner.define_method(name, @cache.instance_method(as))
|
388
|
-
end
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
class << self
|
393
|
-
def batch(owner, path, line)
|
394
|
-
if owner.is_a?(CodeGenerator)
|
395
|
-
yield owner
|
396
|
-
else
|
397
|
-
instance = new(owner, path, line)
|
398
|
-
result = yield instance
|
399
|
-
instance.execute
|
400
|
-
result
|
401
|
-
end
|
402
|
-
end
|
403
|
-
end
|
404
|
-
|
405
|
-
def initialize(owner, path, line)
|
406
|
-
@owner = owner
|
407
|
-
@path = path
|
408
|
-
@line = line
|
409
|
-
@namespaces = Hash.new { |h, k| h[k] = MethodSet.new(k) }
|
410
|
-
end
|
411
|
-
|
412
|
-
def define_cached_method(name, namespace:, as: name, &block)
|
413
|
-
@namespaces[namespace].define_cached_method(name, as: as, &block)
|
414
|
-
end
|
415
|
-
|
416
|
-
def execute
|
417
|
-
@namespaces.each_value do |method_set|
|
418
|
-
method_set.apply(@owner, @path, @line - 1)
|
419
|
-
end
|
420
|
-
end
|
421
|
-
end
|
422
|
-
private_constant :CodeGenerator
|
423
|
-
|
424
361
|
def generated_attribute_methods
|
425
362
|
@generated_attribute_methods ||= Module.new.tap { |mod| include mod }
|
426
363
|
end
|
@@ -144,16 +144,7 @@ module ActiveModel
|
|
144
144
|
end
|
145
145
|
|
146
146
|
def marshal_load(values)
|
147
|
-
|
148
|
-
ActiveSupport::Deprecation.warn(<<~MSG)
|
149
|
-
Marshalling load from legacy attributes format is deprecated and will be removed in Rails 7.0.
|
150
|
-
MSG
|
151
|
-
empty_hash = {}.freeze
|
152
|
-
initialize(empty_hash, empty_hash, empty_hash, empty_hash, values)
|
153
|
-
@materialized = true
|
154
|
-
else
|
155
|
-
initialize(*values)
|
156
|
-
end
|
147
|
+
initialize(*values)
|
157
148
|
end
|
158
149
|
|
159
150
|
protected
|
data/lib/active_model/errors.rb
CHANGED
@@ -63,12 +63,19 @@ module ActiveModel
|
|
63
63
|
include Enumerable
|
64
64
|
|
65
65
|
extend Forwardable
|
66
|
-
def_delegators :@errors, :size, :clear, :blank?, :empty?, :uniq!, :any?
|
67
|
-
# TODO: forward all enumerable methods after `each` deprecation is removed.
|
68
|
-
def_delegators :@errors, :count
|
69
66
|
|
70
|
-
|
71
|
-
|
67
|
+
# :method: each
|
68
|
+
#
|
69
|
+
# :call-seq: each(&block)
|
70
|
+
#
|
71
|
+
# Iterates through each error object.
|
72
|
+
#
|
73
|
+
# person.errors.add(:name, :too_short, count: 2)
|
74
|
+
# person.errors.each do |error|
|
75
|
+
# # Will yield <#ActiveModel::Error attribute=name, type=too_short,
|
76
|
+
# options={:count=>3}>
|
77
|
+
# end
|
78
|
+
def_delegators :@errors, :each, :clear, :empty?, :size, :uniq!
|
72
79
|
|
73
80
|
# The actual array of +Error+ objects
|
74
81
|
# This method is aliased to <tt>objects</tt>.
|
@@ -133,30 +140,13 @@ module ActiveModel
|
|
133
140
|
#
|
134
141
|
# person.errors.merge!(other)
|
135
142
|
def merge!(other)
|
143
|
+
return errors if equal?(other)
|
144
|
+
|
136
145
|
other.errors.each { |error|
|
137
146
|
import(error)
|
138
147
|
}
|
139
148
|
end
|
140
149
|
|
141
|
-
# Removes all errors except the given keys. Returns a hash containing the removed errors.
|
142
|
-
#
|
143
|
-
# person.errors.keys # => [:name, :age, :gender, :city]
|
144
|
-
# person.errors.slice!(:age, :gender) # => { :name=>["cannot be nil"], :city=>["cannot be nil"] }
|
145
|
-
# person.errors.keys # => [:age, :gender]
|
146
|
-
def slice!(*keys)
|
147
|
-
deprecation_removal_warning(:slice!)
|
148
|
-
|
149
|
-
keys = keys.map(&:to_sym)
|
150
|
-
|
151
|
-
results = messages.dup.slice!(*keys)
|
152
|
-
|
153
|
-
@errors.keep_if do |error|
|
154
|
-
keys.include?(error.attribute)
|
155
|
-
end
|
156
|
-
|
157
|
-
results
|
158
|
-
end
|
159
|
-
|
160
150
|
# Search for errors matching +attribute+, +type+ or +options+.
|
161
151
|
#
|
162
152
|
# Only supplied params will be matched.
|
@@ -205,76 +195,7 @@ module ActiveModel
|
|
205
195
|
# person.errors[:name] # => ["cannot be nil"]
|
206
196
|
# person.errors['name'] # => ["cannot be nil"]
|
207
197
|
def [](attribute)
|
208
|
-
|
209
|
-
end
|
210
|
-
|
211
|
-
# Iterates through each error object.
|
212
|
-
#
|
213
|
-
# person.errors.add(:name, :too_short, count: 2)
|
214
|
-
# person.errors.each do |error|
|
215
|
-
# # Will yield <#ActiveModel::Error attribute=name, type=too_short,
|
216
|
-
# options={:count=>3}>
|
217
|
-
# end
|
218
|
-
#
|
219
|
-
# To be backward compatible with past deprecated hash-like behavior,
|
220
|
-
# when block accepts two parameters instead of one, it
|
221
|
-
# iterates through each error key, value pair in the error messages hash.
|
222
|
-
# Yields the attribute and the error for that attribute. If the attribute
|
223
|
-
# has more than one error message, yields once for each error message.
|
224
|
-
#
|
225
|
-
# person.errors.add(:name, :blank, message: "can't be blank")
|
226
|
-
# person.errors.each do |attribute, message|
|
227
|
-
# # Will yield :name and "can't be blank"
|
228
|
-
# end
|
229
|
-
#
|
230
|
-
# person.errors.add(:name, :not_specified, message: "must be specified")
|
231
|
-
# person.errors.each do |attribute, message|
|
232
|
-
# # Will yield :name and "can't be blank"
|
233
|
-
# # then yield :name and "must be specified"
|
234
|
-
# end
|
235
|
-
def each(&block)
|
236
|
-
if block.arity <= 1
|
237
|
-
@errors.each(&block)
|
238
|
-
else
|
239
|
-
ActiveSupport::Deprecation.warn(<<~MSG)
|
240
|
-
Enumerating ActiveModel::Errors as a hash has been deprecated.
|
241
|
-
In Rails 6.1, `errors` is an array of Error objects,
|
242
|
-
therefore it should be accessed by a block with a single block
|
243
|
-
parameter like this:
|
244
|
-
|
245
|
-
person.errors.each do |error|
|
246
|
-
attribute = error.attribute
|
247
|
-
message = error.message
|
248
|
-
end
|
249
|
-
|
250
|
-
You are passing a block expecting two parameters,
|
251
|
-
so the old hash behavior is simulated. As this is deprecated,
|
252
|
-
this will result in an ArgumentError in Rails 7.0.
|
253
|
-
MSG
|
254
|
-
@errors.
|
255
|
-
sort { |a, b| a.attribute <=> b.attribute }.
|
256
|
-
each { |error| yield error.attribute, error.message }
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
# Returns all message values.
|
261
|
-
#
|
262
|
-
# person.errors.messages # => {:name=>["cannot be nil", "must be specified"]}
|
263
|
-
# person.errors.values # => [["cannot be nil", "must be specified"]]
|
264
|
-
def values
|
265
|
-
deprecation_removal_warning(:values, "errors.map { |error| error.message }")
|
266
|
-
@errors.map(&:message).freeze
|
267
|
-
end
|
268
|
-
|
269
|
-
# Returns all message keys.
|
270
|
-
#
|
271
|
-
# person.errors.messages # => {:name=>["cannot be nil", "must be specified"]}
|
272
|
-
# person.errors.keys # => [:name]
|
273
|
-
def keys
|
274
|
-
deprecation_removal_warning(:keys, "errors.attribute_names")
|
275
|
-
keys = @errors.map(&:attribute)
|
276
|
-
keys.uniq!
|
277
|
-
keys.freeze
|
198
|
+
messages_for(attribute)
|
278
199
|
end
|
279
200
|
|
280
201
|
# Returns all error attribute names
|
@@ -285,22 +206,6 @@ module ActiveModel
|
|
285
206
|
@errors.map(&:attribute).uniq.freeze
|
286
207
|
end
|
287
208
|
|
288
|
-
# Returns an xml formatted representation of the Errors hash.
|
289
|
-
#
|
290
|
-
# person.errors.add(:name, :blank, message: "can't be blank")
|
291
|
-
# person.errors.add(:name, :not_specified, message: "must be specified")
|
292
|
-
# person.errors.to_xml
|
293
|
-
# # =>
|
294
|
-
# # <?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
295
|
-
# # <errors>
|
296
|
-
# # <error>name can't be blank</error>
|
297
|
-
# # <error>name must be specified</error>
|
298
|
-
# # </errors>
|
299
|
-
def to_xml(options = {})
|
300
|
-
deprecation_removal_warning(:to_xml)
|
301
|
-
to_a.to_xml({ root: "errors", skip_types: true }.merge!(options))
|
302
|
-
end
|
303
|
-
|
304
209
|
# Returns a Hash that can be used as the JSON representation for this
|
305
210
|
# object. You can pass the <tt>:full_messages</tt> option. This determines
|
306
211
|
# if the json object should contain full messages or not (false by default).
|
@@ -323,33 +228,26 @@ module ActiveModel
|
|
323
228
|
end
|
324
229
|
end
|
325
230
|
|
326
|
-
|
327
|
-
ActiveSupport::Deprecation.warn(<<~EOM)
|
328
|
-
ActiveModel::Errors#to_h is deprecated and will be removed in Rails 7.0.
|
329
|
-
Please use `ActiveModel::Errors.to_hash` instead. The values in the hash
|
330
|
-
returned by `ActiveModel::Errors.to_hash` is an array of error messages.
|
331
|
-
EOM
|
231
|
+
undef :to_h
|
332
232
|
|
333
|
-
|
334
|
-
end
|
233
|
+
EMPTY_ARRAY = [].freeze # :nodoc:
|
335
234
|
|
336
235
|
# Returns a Hash of attributes with an array of their error messages.
|
337
|
-
#
|
338
|
-
# Updating this hash would still update errors state for backward
|
339
|
-
# compatibility, but this behavior is deprecated.
|
340
236
|
def messages
|
341
|
-
|
237
|
+
hash = to_hash
|
238
|
+
hash.default = EMPTY_ARRAY
|
239
|
+
hash.freeze
|
240
|
+
hash
|
342
241
|
end
|
343
242
|
|
344
243
|
# Returns a Hash of attributes with an array of their error details.
|
345
|
-
#
|
346
|
-
# Updating this hash would still update errors state for backward
|
347
|
-
# compatibility, but this behavior is deprecated.
|
348
244
|
def details
|
349
245
|
hash = group_by_attribute.transform_values do |errors|
|
350
246
|
errors.map(&:details)
|
351
247
|
end
|
352
|
-
|
248
|
+
hash.default = EMPTY_ARRAY
|
249
|
+
hash.freeze
|
250
|
+
hash
|
353
251
|
end
|
354
252
|
|
355
253
|
# Returns a Hash of attributes with an array of their Error objects.
|
@@ -550,27 +448,6 @@ module ActiveModel
|
|
550
448
|
Error.generate_message(attribute, type, @base, options)
|
551
449
|
end
|
552
450
|
|
553
|
-
def marshal_load(array) # :nodoc:
|
554
|
-
# Rails 5
|
555
|
-
@errors = []
|
556
|
-
@base = array[0]
|
557
|
-
add_from_legacy_details_hash(array[2])
|
558
|
-
end
|
559
|
-
|
560
|
-
def init_with(coder) # :nodoc:
|
561
|
-
data = coder.map
|
562
|
-
|
563
|
-
data.each { |k, v|
|
564
|
-
next if LEGACY_ATTRIBUTES.include?(k.to_sym)
|
565
|
-
instance_variable_set(:"@#{k}", v)
|
566
|
-
}
|
567
|
-
|
568
|
-
@errors ||= []
|
569
|
-
|
570
|
-
# Legacy support Rails 5.x details hash
|
571
|
-
add_from_legacy_details_hash(data["details"]) if data.key?("details")
|
572
|
-
end
|
573
|
-
|
574
451
|
def inspect # :nodoc:
|
575
452
|
inspection = @errors.inspect
|
576
453
|
|
@@ -586,97 +463,6 @@ module ActiveModel
|
|
586
463
|
|
587
464
|
[attribute.to_sym, type, options]
|
588
465
|
end
|
589
|
-
|
590
|
-
def add_from_legacy_details_hash(details)
|
591
|
-
details.each { |attribute, errors|
|
592
|
-
errors.each { |error|
|
593
|
-
type = error.delete(:error)
|
594
|
-
add(attribute, type, **error)
|
595
|
-
}
|
596
|
-
}
|
597
|
-
end
|
598
|
-
|
599
|
-
def deprecation_removal_warning(method_name, alternative_message = nil)
|
600
|
-
message = +"ActiveModel::Errors##{method_name} is deprecated and will be removed in Rails 7.0."
|
601
|
-
if alternative_message
|
602
|
-
message << "\n\nTo achieve the same use:\n\n "
|
603
|
-
message << alternative_message
|
604
|
-
end
|
605
|
-
ActiveSupport::Deprecation.warn(message)
|
606
|
-
end
|
607
|
-
|
608
|
-
def deprecation_rename_warning(old_method_name, new_method_name)
|
609
|
-
ActiveSupport::Deprecation.warn("ActiveModel::Errors##{old_method_name} is deprecated. Please call ##{new_method_name} instead.")
|
610
|
-
end
|
611
|
-
end
|
612
|
-
|
613
|
-
class DeprecationHandlingMessageHash < SimpleDelegator # :nodoc:
|
614
|
-
def initialize(errors)
|
615
|
-
@errors = errors
|
616
|
-
super(prepare_content)
|
617
|
-
end
|
618
|
-
|
619
|
-
def []=(attribute, value)
|
620
|
-
ActiveSupport::Deprecation.warn("Calling `[]=` to an ActiveModel::Errors is deprecated. Please call `ActiveModel::Errors#add` instead.")
|
621
|
-
|
622
|
-
@errors.delete(attribute)
|
623
|
-
Array(value).each do |message|
|
624
|
-
@errors.add(attribute, message)
|
625
|
-
end
|
626
|
-
|
627
|
-
__setobj__ prepare_content
|
628
|
-
end
|
629
|
-
|
630
|
-
def delete(attribute)
|
631
|
-
ActiveSupport::Deprecation.warn("Calling `delete` to an ActiveModel::Errors messages hash is deprecated. Please call `ActiveModel::Errors#delete` instead.")
|
632
|
-
|
633
|
-
@errors.delete(attribute)
|
634
|
-
end
|
635
|
-
|
636
|
-
private
|
637
|
-
def prepare_content
|
638
|
-
content = @errors.to_hash
|
639
|
-
content.each do |attribute, value|
|
640
|
-
content[attribute] = DeprecationHandlingMessageArray.new(value, @errors, attribute)
|
641
|
-
end
|
642
|
-
content.default_proc = proc do |hash, attribute|
|
643
|
-
hash = hash.dup
|
644
|
-
hash[attribute] = DeprecationHandlingMessageArray.new([], @errors, attribute)
|
645
|
-
__setobj__ hash.freeze
|
646
|
-
hash[attribute]
|
647
|
-
end
|
648
|
-
content.freeze
|
649
|
-
end
|
650
|
-
end
|
651
|
-
|
652
|
-
class DeprecationHandlingMessageArray < SimpleDelegator # :nodoc:
|
653
|
-
def initialize(content, errors, attribute)
|
654
|
-
@errors = errors
|
655
|
-
@attribute = attribute
|
656
|
-
super(content.freeze)
|
657
|
-
end
|
658
|
-
|
659
|
-
def <<(message)
|
660
|
-
ActiveSupport::Deprecation.warn("Calling `<<` to an ActiveModel::Errors message array in order to add an error is deprecated. Please call `ActiveModel::Errors#add` instead.")
|
661
|
-
|
662
|
-
@errors.add(@attribute, message)
|
663
|
-
__setobj__ @errors.messages_for(@attribute)
|
664
|
-
self
|
665
|
-
end
|
666
|
-
|
667
|
-
def clear
|
668
|
-
ActiveSupport::Deprecation.warn("Calling `clear` to an ActiveModel::Errors message array in order to delete all errors is deprecated. Please call `ActiveModel::Errors#delete` instead.")
|
669
|
-
|
670
|
-
@errors.delete(@attribute)
|
671
|
-
end
|
672
|
-
end
|
673
|
-
|
674
|
-
class DeprecationHandlingDetailsHash < SimpleDelegator # :nodoc:
|
675
|
-
def initialize(details)
|
676
|
-
details.default = []
|
677
|
-
details.freeze
|
678
|
-
super(details)
|
679
|
-
end
|
680
466
|
end
|
681
467
|
|
682
468
|
# Raised when a validation cannot be corrected by end users and are considered
|
@@ -94,6 +94,7 @@ module ActiveModel
|
|
94
94
|
|
95
95
|
define_method("#{attribute}=") do |unencrypted_password|
|
96
96
|
if unencrypted_password.nil?
|
97
|
+
instance_variable_set("@#{attribute}", nil)
|
97
98
|
self.public_send("#{attribute}_digest=", nil)
|
98
99
|
elsif !unencrypted_password.empty?
|
99
100
|
instance_variable_set("@#{attribute}", unencrypted_password)
|
@@ -118,7 +119,7 @@ module ActiveModel
|
|
118
119
|
# user.authenticate_password('mUc3m00RsqyRe') # => user
|
119
120
|
define_method("authenticate_#{attribute}") do |unencrypted_password|
|
120
121
|
attribute_digest = public_send("#{attribute}_digest")
|
121
|
-
BCrypt::Password.new(attribute_digest).is_password?(unencrypted_password) && self
|
122
|
+
attribute_digest.present? && BCrypt::Password.new(attribute_digest).is_password?(unencrypted_password) && self
|
122
123
|
end
|
123
124
|
|
124
125
|
alias_method :authenticate, :authenticate_password if attribute == :password
|
@@ -161,7 +161,7 @@ module ActiveModel
|
|
161
161
|
# Configuration options:
|
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
|
-
# integer
|
164
|
+
# integer (default is +false+).
|
165
165
|
# * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+ (default is
|
166
166
|
# +false+). Notice that for Integer and Float columns empty strings are
|
167
167
|
# converted to +nil+.
|
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.0
|
4
|
+
version: 7.0.0
|
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-12-15 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.0
|
19
|
+
version: 7.0.0
|
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.0
|
26
|
+
version: 7.0.0
|
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,10 +107,11 @@ 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.0
|
111
|
-
documentation_uri: https://api.rubyonrails.org/v7.0.0
|
110
|
+
changelog_uri: https://github.com/rails/rails/blob/v7.0.0/activemodel/CHANGELOG.md
|
111
|
+
documentation_uri: https://api.rubyonrails.org/v7.0.0/
|
112
112
|
mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
|
113
|
-
source_code_uri: https://github.com/rails/rails/tree/v7.0.0
|
113
|
+
source_code_uri: https://github.com/rails/rails/tree/v7.0.0/activemodel
|
114
|
+
rubygems_mfa_required: 'true'
|
114
115
|
post_install_message:
|
115
116
|
rdoc_options: []
|
116
117
|
require_paths:
|
@@ -122,11 +123,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
123
|
version: 2.7.0
|
123
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
125
|
requirements:
|
125
|
-
- - "
|
126
|
+
- - ">="
|
126
127
|
- !ruby/object:Gem::Version
|
127
|
-
version:
|
128
|
+
version: '0'
|
128
129
|
requirements: []
|
129
|
-
rubygems_version: 3.
|
130
|
+
rubygems_version: 3.2.32
|
130
131
|
signing_key:
|
131
132
|
specification_version: 4
|
132
133
|
summary: A toolkit for building modeling frameworks (part of Rails).
|