This repository has been archived by the owner on Jul 5, 2023. It is now read-only.
/
activemodel.rbi
715 lines (646 loc) · 22.6 KB
/
activemodel.rbi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
# This file is autogenerated. Do not edit it by hand. Regenerate it with:
# srb rbi sorbet-typed
#
# If you would like to make changes to this file, great! Please upstream any changes you make here:
#
# https://github.com/sorbet/sorbet-typed/edit/master/lib/activemodel/all/activemodel.rbi
#
# typed: false
module ActiveModel::AttributeMethods
mixes_in_class_methods(::ActiveModel::AttributeMethods::ClassMethods)
end
module ActiveModel::AttributeMethods::ClassMethods; end
ActiveModel::AttributeMethods::AttrNames::DEF_SAFE_NAME = T.let(T.unsafe(nil), Regexp)
ActiveModel::AttributeMethods::CALL_COMPILABLE_REGEXP = T.let(T.unsafe(nil), Regexp)
ActiveModel::AttributeMethods::NAME_COMPILABLE_REGEXP = T.let(T.unsafe(nil), Regexp)
module ActiveModel::Conversion
mixes_in_class_methods(::ActiveModel::Conversion::ClassMethods)
end
module ActiveModel::Conversion::ClassMethods; end
module ActiveModel::Dirty
include(::ActiveModel::AttributeMethods)
sig { params(attr: Symbol, from: T.untyped, to: T.untyped).returns(T::Boolean) }
def attribute_changed?(attr, from: nil, to: nil); end
sig { params(attr_name: Symbol).returns(T::Boolean) }
def attribute_changed_in_place?(attr_name); end
sig { params(attr_name: Symbol, options: T.untyped).returns(T::Boolean) }
def attribute_previously_changed?(attr_name, **options); end
sig { returns(T::Boolean) }
def changed?; end
sig { returns(T::Hash[T.any(Symbol, String), T.untyped]) }
def previous_changes; end
end
class ActiveModel::ForbiddenAttributesError < ::StandardError
end
module ActiveModel::Model
include(::ActiveModel::AttributeAssignment)
extend(::ActiveSupport::Concern)
include(::ActiveSupport::Callbacks)
include(::ActiveModel::Validations::HelperMethods)
include(::ActiveModel::Validations)
include(::ActiveModel::Conversion)
end
module ActiveModel::Validations
extend(::ActiveSupport::Concern)
include(::ActiveSupport::Callbacks)
include(::ActiveModel::Validations::HelperMethods)
mixes_in_class_methods(::ActiveModel::Validations::ClassMethods)
# Returns the `Errors` object that holds all information about attribute
# error messages.
#
# ```ruby
# class Person
# include ActiveModel::Validations
#
# attr_accessor :name
# validates_presence_of :name
# end
#
# person = Person.new
# person.valid? # => false
# person.errors # => #<ActiveModel::Errors:0x007fe603816640 @messages={name:["can't be blank"]}>
# ```
sig { returns(ActiveModel::Errors) }
def errors; end
sig { params(context: T.untyped).returns(T::Boolean) }
def invalid?(context = T.unsafe(nil)); end
sig { params(context: T.untyped).returns(T::Boolean) }
def valid?(context = T.unsafe(nil)); end
end
module ActiveModel::Validations::ClassMethods
# https://github.com/rails/rails/blob/v5.2.3/activemodel/lib/active_model/validations.rb#L136-L154
sig do
params(
names: T.any(Symbol, String),
if: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
on: T.any(Symbol, String, T::Array[T.any(Symbol, String)]),
prepend: T::Boolean,
unless: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
).void
end
def validate(
*names,
if: nil,
on: nil,
prepend: false,
unless: nil
); end
# https://github.com/rails/rails/blob/v5.2.3/activemodel/lib/active_model/validations/validates.rb#L75-L105
sig do
params(
names: T.any(Symbol, String), # a splat of at least one attribute name
absence: T.any(T::Boolean, T::Hash[T.untyped, T.untyped]),
acceptance: T.any(T::Boolean, T::Hash[T.untyped, T.untyped]),
allow_blank: T::Boolean,
allow_nil: T::Boolean,
confirmation: T.any(T::Boolean, T::Hash[T.untyped, T.untyped]),
# `exclusion` and `inclusion` are tricky to type without better support
# for overloading and shapes. Value can be anything that responds to
# `include?` (e.g. (1..3)), or a hash having an `in` or `within` key,
# like { in: [1, 2, 3], ... }
exclusion: T::Enumerable[T.untyped],
# `format` hash must additionally contain either :with or :without keys.
# Alternatively, it can be a Regexp.
format: T.any(T::Hash[T.untyped, T.untyped], Regexp),
if: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
# `exclusion` and `inclusion` are tricky to type without better support
# for overloading and shapes. Value can be anything that responds to
# `include?` (e.g. (1..3)), or a hash having an `in` or `within` key,
# like { in: [1, 2, 3], ... }
inclusion: T::Enumerable[T.untyped],
# if Hash, must contain :in, :within, :maximum, :minimum, or :is keys
length: T.any(T::Range[T.untyped], T::Hash[T.untyped, T.untyped]),
numericality: T.any(T::Boolean, T::Hash[T.untyped, T.untyped]),
on: T.any(Symbol, String, T::Array[T.any(Symbol, String)]),
presence: T.any(T::Boolean, T::Hash[T.untyped, T.untyped]),
size: T.any(T::Boolean, T::Hash[T.untyped, T.untyped]),
strict: T::Boolean,
uniqueness: T.any(T::Boolean, T::Hash[T.untyped, T.untyped]),
unless: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
kwargs: T.untyped
).void
end
def validates(
*names,
absence: false,
acceptance: {},
allow_blank: false,
allow_nil: false,
confirmation: false,
exclusion: [],
format: {},
if: nil,
inclusion: [],
length: {},
numericality: false,
on: :_,
presence: false,
size: false,
strict: false,
uniqueness: false,
unless: :_,
**kwargs
)
end
end
ActiveModel::Validations::ClassMethods::VALID_OPTIONS_FOR_VALIDATE = T.let(T.unsafe(nil), T::Array[T.untyped])
module ActiveModel::SecurePassword
mixes_in_class_methods(::ActiveModel::SecurePassword::ClassMethods)
end
module ActiveModel::SecurePassword::ClassMethods; end
ActiveModel::SecurePassword::MAX_PASSWORD_LENGTH_ALLOWED = T.let(T.unsafe(nil), Integer)
class ActiveModel::Type::Value
extend T::Sig
sig { params(precision: T.untyped, limit: T.untyped, scale: T.untyped).void }
def initialize(precision: nil, limit: nil, scale: nil); end
sig { params(value: T.untyped).returns(T.untyped) }
def cast(value); end
end
class ActiveModel::Type::Boolean < ActiveModel::Type::Value
sig { params(arg0: T.untyped).returns(T.nilable(T::Boolean)) }
def cast(arg0); end
end
class ActiveModel::Type::ImmutableString < ActiveModel::Type::Value
sig { params(arg0: T.untyped).returns(T.nilable(String)) }
def cast(arg0); end
end
class ActiveModel::Type::String < ActiveModel::Type::ImmutableString; end
class ActiveModel::Type::Integer < ActiveModel::Type::Value
sig { params(arg0: T.untyped).returns(T.nilable(Integer)) }
def cast(arg0); end
end
class ActiveModel::Type::BigInteger < ActiveModel::Type::Integer; end
class ActiveModel::Type::Binary < ActiveModel::Type::Value
sig { params(arg0: T.untyped).returns(T.nilable(String)) }
def cast(arg0); end
end
class ActiveModel::Type::Decimal < ActiveModel::Type::Value
sig { params(arg0: T.untyped).returns(T.nilable(BigDecimal)) }
def cast(arg0); end
end
class ActiveModel::Type::Float < ActiveModel::Type::Value
sig { params(arg0: T.untyped).returns(T.nilable(Float)) }
def cast(arg0); end
end
class ActiveModel::Type::Date < ::ActiveModel::Type::Value
sig { params(arg0: T.untyped).returns(T.nilable(Date)) }
def cast(arg0); end
end
class ActiveModel::Type::DateTime < ::ActiveModel::Type::Value
sig { params(arg0: T.untyped).returns(T.nilable(DateTime)) }
def cast(arg0); end
end
module ActiveModel::Validations::Callbacks
mixes_in_class_methods(::ActiveModel::Validations::Callbacks::ClassMethods)
end
module ActiveModel::Validations::Callbacks::ClassMethods; end
module ActiveModel::Validations::HelperMethods
# A type alias for the in/within parameters on the
# validates_(inclusion/exclusion)_of methods.
InWithinType = T.type_alias do
T.nilable(
T.any(
Symbol,
String,
T::Array[T.any(String, Symbol)],
T::Range[Integer],
T::Array[T::Boolean],
T.proc.params(arg0: T.untyped).returns(T::Boolean)
)
)
end
module ClassMethods
sig do
params(
attr_names: T.any(String, Symbol),
message: String,
if: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
unless: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
on: T.any(Symbol, String, T::Array[T.any(Symbol, String)]),
allow_nil: T::Boolean,
allow_blank: T::Boolean,
strict: T::Boolean
).void
end
def validates_absence_of(
*attr_names,
message: 'must be blank',
if: nil,
unless: :_,
on: :_,
allow_nil: false,
allow_blank: false,
strict: false
); end
sig do
params(
attr_names: T.any(String, Symbol),
message: String,
accept: T.untyped,
if: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
unless: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
on: T.any(Symbol, String, T::Array[T.any(Symbol, String)]),
allow_nil: T::Boolean,
allow_blank: T::Boolean,
strict: T::Boolean
).void
end
def validates_acceptance_of(
*attr_names,
message: 'must be accepted',
accept: ['1', true],
if: nil,
unless: :_,
on: :_,
allow_nil: false,
allow_blank: false,
strict: false
); end
sig do
params(
attr_names: T.any(String, Symbol),
message: String,
case_sensitive: T::Boolean,
if: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
unless: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
on: T.any(Symbol, String, T::Array[T.any(Symbol, String)]),
allow_nil: T::Boolean,
allow_blank: T::Boolean,
strict: T::Boolean
).void
end
def validates_confirmation_of(
*attr_names,
message: "doesn't match %{translated_attribute_name}",
case_sensitive: true,
if: nil,
unless: :_,
on: :_,
allow_nil: false,
allow_blank: false,
strict: false
); end
sig do
params(
attr_names: T.any(String, Symbol),
message: String,
in: InWithinType,
within: InWithinType,
if: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
unless: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
on: T.any(Symbol, String, T::Array[T.any(Symbol, String)]),
allow_nil: T::Boolean,
allow_blank: T::Boolean,
strict: T::Boolean
).void
end
def validates_exclusion_of(
*attr_names,
message: 'is reserved',
in: nil,
within: nil,
if: nil,
unless: :_,
on: :_,
allow_nil: false,
allow_blank: false,
strict: false
); end
sig do
params(
attr_names: T.any(String, Symbol),
message: String,
with: T.untyped,
without: T.untyped,
multiline: T.untyped,
if: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
unless: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
on: T.any(Symbol, String, T::Array[T.any(Symbol, String)]),
allow_nil: T::Boolean,
allow_blank: T::Boolean,
strict: T::Boolean
).void
end
def validates_format_of(
*attr_names,
message: 'is invalid',
with: nil,
without: nil,
multiline: nil,
if: nil,
unless: :_,
on: :_,
allow_nil: false,
allow_blank: false,
strict: false
); end
sig do
params(
attr_names: T.any(String, Symbol),
message: String,
in: InWithinType,
within: InWithinType,
if: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
unless: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
on: T.any(Symbol, String, T::Array[T.any(Symbol, String)]),
allow_nil: T::Boolean,
allow_blank: T::Boolean,
strict: T::Boolean
).void
end
def validates_inclusion_of(
*attr_names,
message: 'is not included in the list',
in: nil,
within: nil,
if: nil,
unless: :_,
on: :_,
allow_nil: false,
allow_blank: false,
strict: false
); end
sig do
params(
attr_names: T.any(String, Symbol),
message: T.nilable(String),
minimum: T.nilable(Integer),
maximum: T.nilable(Integer),
is: T.nilable(Integer),
within: T.nilable(T::Range[Integer]),
in: T.nilable(T::Range[Integer]),
too_long: String,
too_short: String,
wrong_length: String,
if: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
unless: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
on: T.any(Symbol, String, T::Array[T.any(Symbol, String)]),
allow_nil: T::Boolean,
allow_blank: T::Boolean,
strict: T::Boolean
).void
end
def validates_length_of(
*attr_names,
message: nil,
minimum: nil,
maximum: nil,
is: nil,
within: nil,
in: nil,
too_long: 'is too long (maximum is %{count} characters)',
too_short: 'is too short (minimum is %{count} characters)',
wrong_length: 'is the wrong length (should be %{count} characters)',
if: nil,
unless: :_,
on: :_,
allow_nil: false,
allow_blank: false,
strict: false
); end
# validates_size_of is an alias of validates_length_of
sig do
params(
attr_names: T.any(String, Symbol),
message: T.nilable(String),
minimum: T.nilable(Integer),
maximum: T.nilable(Integer),
is: T.nilable(Integer),
within: T.nilable(T::Range[Integer]),
in: T.nilable(T::Range[Integer]),
too_long: String,
too_short: String,
wrong_length: String,
if: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
unless: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
on: T.any(Symbol, String, T::Array[T.any(Symbol, String)]),
allow_nil: T::Boolean,
allow_blank: T::Boolean,
strict: T::Boolean
).void
end
def validates_size_of(
*attr_names,
message: nil,
minimum: nil,
maximum: nil,
is: nil,
within: nil,
in: nil,
too_long: 'is too long (maximum is %{count} characters)',
too_short: 'is too short (minimum is %{count} characters)',
wrong_length: 'is the wrong length (should be %{count} characters)',
if: nil,
unless: :_,
on: :_,
allow_nil: false,
allow_blank: false,
strict: false
); end
# Create a type alias so we don't have to repeat this long type signature 6 times.
NumberComparatorType = T.type_alias {T.nilable(T.any(Integer, Float, T.proc.params(arg0: T.untyped).returns(T::Boolean), Symbol))}
sig do
params(
attr_names: T.any(String, Symbol),
message: String,
only_integer: T::Boolean,
greater_than: NumberComparatorType,
greater_than_or_equal_to: NumberComparatorType,
equal_to: NumberComparatorType,
less_than: NumberComparatorType,
less_than_or_equal_to: NumberComparatorType,
other_than: NumberComparatorType,
odd: T::Boolean,
even: T::Boolean,
if: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
unless: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
on: T.any(Symbol, String, T::Array[T.any(Symbol, String)]),
allow_nil: T::Boolean,
allow_blank: T::Boolean,
strict: T::Boolean
).void
end
def validates_numericality_of(
*attr_names,
message: 'is not a number',
only_integer: false,
greater_than: nil,
greater_than_or_equal_to: nil,
equal_to: nil,
less_than: nil,
less_than_or_equal_to: nil,
other_than: nil,
odd: false,
even: false,
if: nil,
unless: :_,
on: :_,
allow_nil: false,
allow_blank: false,
strict: false
); end
sig do
params(
attr_names: T.any(String, Symbol),
message: String,
if: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
unless: T.any(Symbol, String, T.proc.params(arg0: T.untyped).returns(T::Boolean)),
on: T.any(Symbol, String, T::Array[T.any(Symbol, String)]),
allow_nil: T::Boolean,
allow_blank: T::Boolean,
strict: T::Boolean
).void
end
def validates_presence_of(
*attr_names,
message: "can't be blank",
if: nil,
unless: :_,
on: :_,
allow_nil: false,
allow_blank: false,
strict: false
); end
end
mixes_in_class_methods(ClassMethods)
end
ActiveModel::Validations::NumericalityValidator::CHECKS = T.let(T.unsafe(nil), T::Hash[T.untyped, T.untyped])
ActiveModel::Validations::NumericalityValidator::HEXADECIMAL_REGEX = T.let(T.unsafe(nil), Regexp)
ActiveModel::Validations::NumericalityValidator::INTEGER_REGEX = T.let(T.unsafe(nil), Regexp)
ActiveModel::Validations::NumericalityValidator::RESERVED_OPTIONS = T.let(T.unsafe(nil), T::Array[T.untyped])
class ActiveModel::Errors
include Enumerable
Elem = type_member {{fixed: T.untyped}}
sig { params(key: T.any(String, Symbol)).returns(T::Array[String]) }
def [](key); end
def each(&blk); end
# Adds `message` to the error messages and used validator type to `details` on `attribute`.
# More than one error can be added to the same `attribute`.
# If no `message` is supplied, `:invalid` is assumed.
#
# ```ruby
# person.errors.add(:name)
# # => ["is invalid"]
# person.errors.add(:name, :not_implemented, message: "must be implemented")
# # => ["is invalid", "must be implemented"]
# ```
#
# ```ruby
# person.errors.messages
# # => {:name=>["is invalid", "must be implemented"]}
# ```
#
# ```ruby
# person.errors.details
# # => {:name=>[{error: :not_implemented}, {error: :invalid}]}
# ```
#
# If `message` is a symbol, it will be translated using the appropriate
# scope (see `generate_message`).
#
# If `message` is a proc, it will be called, allowing for things like
# `Time.now` to be used within an error.
#
# If the `:strict` option is set to `true`, it will raise
# ActiveModel::StrictValidationFailed instead of adding the error.
# `:strict` option can also be set to any other exception.
#
# ```ruby
# person.errors.add(:name, :invalid, strict: true)
# # => ActiveModel::StrictValidationFailed: Name is invalid
# person.errors.add(:name, :invalid, strict: NameIsInvalid)
# # => NameIsInvalid: Name is invalid
#
# person.errors.messages # => {}
# ```
#
# `attribute` should be set to `:base` if the error is not
# directly associated with a single attribute.
#
# ```ruby
# person.errors.add(:base, :name_or_email_blank,
# message: "either name or email must be present")
# person.errors.messages
# # => {:base=>["either name or email must be present"]}
# person.errors.details
# # => {:base=>[{error: :name_or_email_blank}]}
# ```
sig do
params(
attribute: T.any(Symbol, String),
message: T.any(String, Symbol),
options: T::Hash[T.untyped, T.untyped]
).returns(T.untyped)
end
def add(attribute, message = :invalid, options = {}); end
# Returns `true` if an error on the attribute with the given message is
# present, or `false` otherwise. `message` is treated the same as for `add`.
#
# ```ruby
# person.errors.add :name, :blank
# person.errors.added? :name, :blank # => true
# person.errors.added? :name, "can't be blank" # => true
# ```
#
# If the error message requires options, then it returns `true` with
# the correct options, or `false` with incorrect or missing options.
#
# ```ruby
# person.errors.add :name, :too_long, { count: 25 }
# person.errors.added? :name, :too_long, count: 25 # => true
# person.errors.added? :name, "is too long (maximum is 25 characters)" # => true
# person.errors.added? :name, :too_long, count: 24 # => false
# person.errors.added? :name, :too_long # => false
# person.errors.added? :name, "is too long" # => false
# ```
sig do
params(
attribute: Symbol,
message: T.any(String, Symbol),
options: T::Hash[T.untyped, T.untyped]
).returns(T::Boolean)
end
def added?(attribute, message = :invalid, options = {}); end
# Returns `true` if an error on the attribute with the given message is
# present, or `false` otherwise. `message` is treated the same as for `add`.
#
# ```ruby
# person.errors.add :age
# person.errors.add :name, :too_long, { count: 25 }
# person.errors.of_kind? :age # => true
# person.errors.of_kind? :name # => false
# person.errors.of_kind? :name, :too_long # => true
# person.errors.of_kind? :name, "is too long (maximum is 25 characters)" # => true
# person.errors.of_kind? :name, :not_too_long # => false
# person.errors.of_kind? :name, "is too long" # => false
# ```
sig do
params(
attribute: Symbol,
message: T.any(String, Symbol)
).returns(T::Boolean)
end
def of_kind?(attribute, message = :invalid); end
# Returns all the full error messages in an array.
#
# ```ruby
# class Person
# validates_presence_of :name, :address, :email
# validates_length_of :name, in: 5..30
# end
#
# person = Person.create(address: '123 First St.')
# person.errors.full_messages
# # => ["Name is too short (minimum is 5 characters)", "Name can't be blank", "Email can't be blank"]
# ```
sig { returns(T::Array[String]) }
def full_messages; end
sig { returns(T::Hash[Symbol, T::Array[String]]) }
def messages; end
sig { params(args: T.untyped, block: T.untyped).returns(T::Boolean) }
def empty?(*args, &block); end
sig { params(full_messages: T::Boolean).returns(T::Hash[Symbol, T::Array[String]]) }
def to_hash(full_messages = false); end
end
ActiveModel::Errors::CALLBACKS_OPTIONS = T.let(T.unsafe(nil), T::Array[T.untyped])
ActiveModel::Errors::MESSAGE_OPTIONS = T.let(T.unsafe(nil), T::Array[T.untyped])