rbs_rails 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,152 @@
1
+ module ActiveModel
2
+ class Attribute
3
+ class UserProvidedDefault < FromUser
4
+ # :nodoc:
5
+ # :nodoc:
6
+ def initialize: (untyped name, untyped value, untyped `type`, untyped database_default) -> untyped
7
+
8
+ def value_before_type_cast: () -> untyped
9
+
10
+ def with_type: (untyped `type`) -> untyped
11
+
12
+ def marshal_dump: () -> untyped
13
+
14
+ def marshal_load: (untyped values) -> untyped
15
+
16
+ attr_reader user_provided_value: untyped
17
+ end
18
+ end
19
+ end
20
+
21
+ module ActiveModel
22
+ class Attribute
23
+ def self.from_database: (untyped name, untyped value, untyped `type`) -> FromDatabase
24
+
25
+ def self.from_user: (untyped name, untyped value, untyped `type`, ?untyped? original_attribute) -> FromUser
26
+
27
+ def self.with_cast_value: (untyped name, untyped value, untyped `type`) -> WithCastValue
28
+
29
+ def self.null: (untyped name) -> Null
30
+
31
+ def self.uninitialized: (untyped name, untyped `type`) -> Uninitialized
32
+
33
+ attr_reader name: untyped
34
+
35
+ attr_reader value_before_type_cast: untyped
36
+
37
+ attr_reader type: untyped
38
+
39
+ # This method should not be called directly.
40
+ # Use #from_database or #from_user
41
+ def initialize: (untyped name, untyped value_before_type_cast, untyped `type`, ?untyped? original_attribute) -> untyped
42
+
43
+ def value: () -> untyped
44
+
45
+ def original_value: () -> untyped
46
+
47
+ def value_for_database: () -> untyped
48
+
49
+ def changed?: () -> untyped
50
+
51
+ def changed_in_place?: () -> untyped
52
+
53
+ def forgetting_assignment: () -> untyped
54
+
55
+ def with_value_from_user: (untyped value) -> untyped
56
+
57
+ def with_value_from_database: (untyped value) -> untyped
58
+
59
+ def with_cast_value: (untyped value) -> untyped
60
+
61
+ def with_type: (untyped `type`) -> untyped
62
+
63
+ def type_cast: () -> untyped
64
+
65
+ def initialized?: () -> ::TrueClass
66
+
67
+ def came_from_user?: () -> ::FalseClass
68
+
69
+ def has_been_read?: () -> untyped
70
+
71
+ def ==: (untyped other) -> untyped
72
+
73
+ alias eql? ==
74
+
75
+ def hash: () -> untyped
76
+
77
+ def init_with: (untyped coder) -> untyped
78
+
79
+ def encode_with: (untyped coder) -> untyped
80
+
81
+ def original_value_for_database: () -> untyped
82
+
83
+ attr_reader original_attribute: untyped
84
+
85
+ alias assigned? original_attribute
86
+
87
+ def initialize_dup: (untyped other) -> untyped
88
+
89
+ def changed_from_assignment?: () -> untyped
90
+
91
+ def _original_value_for_database: () -> untyped
92
+
93
+ class FromDatabase < Attribute
94
+ # :nodoc:
95
+ def type_cast: (untyped value) -> untyped
96
+
97
+ def _original_value_for_database: () -> untyped
98
+ end
99
+
100
+ class FromUser < Attribute
101
+ # :nodoc:
102
+ def type_cast: (untyped value) -> untyped
103
+
104
+ def came_from_user?: () -> untyped
105
+ end
106
+
107
+ class WithCastValue < Attribute
108
+ # :nodoc:
109
+ def type_cast: (untyped value) -> untyped
110
+
111
+ def changed_in_place?: () -> ::FalseClass
112
+ end
113
+
114
+ class Null < Attribute
115
+ # :nodoc:
116
+ def initialize: (untyped name) -> untyped
117
+
118
+ def type_cast: () -> nil
119
+
120
+ def with_type: (untyped `type`) -> untyped
121
+
122
+ def with_value_from_database: (untyped value) -> untyped
123
+
124
+ alias with_value_from_user with_value_from_database
125
+
126
+ alias with_cast_value with_value_from_database
127
+ end
128
+
129
+ class Uninitialized < Attribute
130
+ # :nodoc:
131
+ UNINITIALIZED_ORIGINAL_VALUE: untyped
132
+
133
+ def initialize: (untyped name, untyped `type`) -> untyped
134
+
135
+ def value: () { (untyped) -> untyped } -> untyped
136
+
137
+ def original_value: () -> untyped
138
+
139
+ def value_for_database: () -> nil
140
+
141
+ def initialized?: () -> ::FalseClass
142
+
143
+ def forgetting_assignment: () -> untyped
144
+
145
+ def with_type: (untyped `type`) -> untyped
146
+ end
147
+ end
148
+ end
149
+
1
150
  module ActiveModel
2
151
  module AttributeAssignment
3
152
  include ActiveModel::ForbiddenAttributesProtection
@@ -23,6 +172,8 @@ module ActiveModel
23
172
  # cat.status # => 'sleeping'
24
173
  def assign_attributes: (untyped new_attributes) -> (nil | untyped)
25
174
 
175
+ alias attributes= assign_attributes
176
+
26
177
  def _assign_attributes: (untyped attributes) -> untyped
27
178
 
28
179
  def _assign_attribute: (untyped k, untyped v) -> untyped
@@ -341,7 +492,7 @@ module ActiveModel
341
492
  # nodoc:
342
493
  attr_reader target: untyped
343
494
 
344
- class AttributeMethodMatch < ::Struct[untyped]
495
+ class AttributeMethodMatch[T] < ::Struct[T]
345
496
  attr_accessor target(): untyped
346
497
 
347
498
  attr_accessor attr_name(): untyped
@@ -375,6 +526,11 @@ module ActiveModel
375
526
  # attribute. This method can be overloaded to customize the behavior.
376
527
  def attribute_missing: (untyped match, *untyped args) { () -> untyped } -> untyped
377
528
 
529
+ # A +Person+ instance with a +name+ attribute can ask
530
+ # <tt>person.respond_to?(:name)</tt>, <tt>person.respond_to?(:name=)</tt>,
531
+ # and <tt>person.respond_to?(:name?)</tt> which will all return +true+.
532
+ alias respond_to_without_attributes? respond_to?
533
+
378
534
  def respond_to?: (untyped method, ?bool include_private_methods) -> untyped
379
535
 
380
536
  def attribute_method?: (untyped attr_name) -> untyped
@@ -431,7 +587,7 @@ module ActiveModel
431
587
 
432
588
  def any_changes?: () -> untyped
433
589
 
434
- def changed?: (untyped attr_name, ?to: untyped to, ?from: untyped from) -> untyped
590
+ def changed?: (untyped attr_name, ?from: untyped from, ?to: untyped to) -> untyped
435
591
 
436
592
  def changed_in_place?: (untyped attr_name) -> untyped
437
593
 
@@ -502,205 +658,103 @@ module ActiveModel
502
658
  end
503
659
 
504
660
  module ActiveModel
505
- class Attribute
506
- def self.from_database: (untyped name, untyped value, untyped `type`) -> FromDatabase
661
+ class AttributeSet
662
+ class Builder
663
+ # :nodoc:
664
+ # :nodoc:
665
+ attr_reader types: untyped
507
666
 
508
- def self.from_user: (untyped name, untyped value, untyped `type`, ?untyped? original_attribute) -> FromUser
667
+ # :nodoc:
668
+ # :nodoc:
669
+ attr_reader default_attributes: untyped
509
670
 
510
- def self.with_cast_value: (untyped name, untyped value, untyped `type`) -> WithCastValue
671
+ def initialize: (untyped types, ?::Hash[untyped, untyped] default_attributes) -> untyped
511
672
 
512
- def self.null: (untyped name) -> Null
673
+ def build_from_database: (?::Hash[untyped, untyped] values, ?::Hash[untyped, untyped] additional_types) -> AttributeSet
674
+ end
675
+ end
513
676
 
514
- def self.uninitialized: (untyped name, untyped `type`) -> Uninitialized
677
+ class LazyAttributeHash
678
+ def initialize: (untyped types, untyped values, untyped additional_types, untyped default_attributes, ?::Hash[untyped, untyped] delegate_hash) -> untyped
515
679
 
516
- attr_reader name: untyped
680
+ def key?: (untyped key) -> untyped
517
681
 
518
- attr_reader value_before_type_cast: untyped
682
+ def []: (untyped key) -> untyped
519
683
 
520
- attr_reader type: untyped
684
+ def []=: (untyped key, untyped value) -> untyped
521
685
 
522
- # This method should not be called directly.
523
- # Use #from_database or #from_user
524
- def initialize: (untyped name, untyped value_before_type_cast, untyped `type`, ?untyped? original_attribute) -> untyped
686
+ def deep_dup: () -> untyped
525
687
 
526
- def value: () -> untyped
688
+ def initialize_dup: (untyped _) -> untyped
527
689
 
528
- def original_value: () -> untyped
690
+ def select: () { (untyped, untyped) -> untyped } -> untyped
529
691
 
530
- def value_for_database: () -> untyped
692
+ def ==: (untyped other) -> untyped
531
693
 
532
- def changed?: () -> untyped
694
+ def marshal_dump: () -> ::Array[untyped]
533
695
 
534
- def changed_in_place?: () -> untyped
696
+ def marshal_load: (untyped values) -> untyped
535
697
 
536
- def forgetting_assignment: () -> untyped
698
+ def materialize: () -> untyped
537
699
 
538
- def with_value_from_user: (untyped value) -> untyped
700
+ attr_reader types: untyped
539
701
 
540
- def with_value_from_database: (untyped value) -> untyped
702
+ attr_reader values: untyped
541
703
 
542
- def with_cast_value: (untyped value) -> untyped
704
+ attr_reader additional_types: untyped
543
705
 
544
- def with_type: (untyped `type`) -> untyped
706
+ attr_reader delegate_hash: untyped
545
707
 
546
- def type_cast: () -> untyped
708
+ attr_reader default_attributes: untyped
547
709
 
548
- def initialized?: () -> ::TrueClass
710
+ def assign_default_value: (untyped name) -> untyped
711
+ end
712
+ end
549
713
 
550
- def came_from_user?: () -> ::FalseClass
714
+ module ActiveModel
715
+ class AttributeSet
716
+ class YAMLEncoder
717
+ # Attempts to do more intelligent YAML dumping of an
718
+ # ActiveModel::AttributeSet to reduce the size of the resulting string
719
+ # :nodoc:
720
+ def initialize: (untyped default_types) -> untyped
551
721
 
552
- def has_been_read?: () -> untyped
722
+ def encode: (untyped attribute_set, untyped coder) -> untyped
553
723
 
554
- def ==: (untyped other) -> untyped
724
+ def decode: (untyped coder) -> untyped
555
725
 
556
- def hash: () -> untyped
726
+ attr_reader default_types: untyped
727
+ end
728
+ end
729
+ end
557
730
 
558
- def init_with: (untyped coder) -> untyped
731
+ module ActiveModel
732
+ class AttributeSet
733
+ def initialize: (untyped attributes) -> untyped
559
734
 
560
- def encode_with: (untyped coder) -> untyped
735
+ def []: (untyped name) -> untyped
561
736
 
562
- def original_value_for_database: () -> untyped
737
+ def []=: (untyped name, untyped value) -> untyped
563
738
 
564
- attr_reader original_attribute: untyped
739
+ def values_before_type_cast: () -> untyped
565
740
 
566
- def initialize_dup: (untyped other) -> untyped
741
+ def to_hash: () -> untyped
567
742
 
568
- def changed_from_assignment?: () -> untyped
743
+ alias to_h to_hash
569
744
 
570
- def _original_value_for_database: () -> untyped
745
+ def key?: (untyped name) -> untyped
571
746
 
572
- class FromDatabase < Attribute
573
- # :nodoc:
574
- def type_cast: (untyped value) -> untyped
747
+ def keys: () -> untyped
575
748
 
576
- def _original_value_for_database: () -> untyped
577
- end
749
+ def fetch_value: (untyped name) { () -> untyped } -> untyped
578
750
 
579
- class FromUser < Attribute
580
- # :nodoc:
581
- def type_cast: (untyped value) -> untyped
751
+ def write_from_database: (untyped name, untyped value) -> untyped
582
752
 
583
- def came_from_user?: () -> untyped
584
- end
753
+ def write_from_user: (untyped name, untyped value) -> untyped
585
754
 
586
- class WithCastValue < Attribute
587
- # :nodoc:
588
- def type_cast: (untyped value) -> untyped
755
+ def write_cast_value: (untyped name, untyped value) -> untyped
589
756
 
590
- def changed_in_place?: () -> ::FalseClass
591
- end
592
-
593
- class Null < Attribute
594
- # :nodoc:
595
- def initialize: (untyped name) -> untyped
596
-
597
- def type_cast: () -> nil
598
-
599
- def with_type: (untyped `type`) -> untyped
600
-
601
- def with_value_from_database: (untyped value) -> untyped
602
- end
603
-
604
- class Uninitialized < Attribute
605
- # :nodoc:
606
- UNINITIALIZED_ORIGINAL_VALUE: untyped
607
-
608
- def initialize: (untyped name, untyped `type`) -> untyped
609
-
610
- def value: () { (untyped) -> untyped } -> untyped
611
-
612
- def original_value: () -> untyped
613
-
614
- def value_for_database: () -> nil
615
-
616
- def initialized?: () -> ::FalseClass
617
-
618
- def forgetting_assignment: () -> untyped
619
-
620
- def with_type: (untyped `type`) -> untyped
621
- end
622
- end
623
- end
624
-
625
- module ActiveModel
626
- class AttributeSet
627
- class Builder
628
- # :nodoc:
629
- # :nodoc:
630
- attr_reader types: untyped
631
-
632
- # :nodoc:
633
- # :nodoc:
634
- attr_reader default_attributes: untyped
635
-
636
- def initialize: (untyped types, ?::Hash[untyped, untyped] default_attributes) -> untyped
637
-
638
- def build_from_database: (?::Hash[untyped, untyped] values, ?::Hash[untyped, untyped] additional_types) -> AttributeSet
639
- end
640
- end
641
-
642
- class LazyAttributeHash
643
- def initialize: (untyped types, untyped values, untyped additional_types, untyped default_attributes, ?::Hash[untyped, untyped] delegate_hash) -> untyped
644
-
645
- def key?: (untyped key) -> untyped
646
-
647
- def []: (untyped key) -> untyped
648
-
649
- def []=: (untyped key, untyped value) -> untyped
650
-
651
- def deep_dup: () -> untyped
652
-
653
- def initialize_dup: (untyped _) -> untyped
654
-
655
- def select: () { (untyped, untyped) -> untyped } -> untyped
656
-
657
- def ==: (untyped other) -> untyped
658
-
659
- def marshal_dump: () -> ::Array[untyped]
660
-
661
- def marshal_load: (untyped values) -> untyped
662
-
663
- def materialize: () -> untyped
664
-
665
- attr_reader types: untyped
666
-
667
- attr_reader values: untyped
668
-
669
- attr_reader additional_types: untyped
670
-
671
- attr_reader delegate_hash: untyped
672
-
673
- attr_reader default_attributes: untyped
674
-
675
- def assign_default_value: (untyped name) -> untyped
676
- end
677
- end
678
-
679
- module ActiveModel
680
- class AttributeSet
681
- def initialize: (untyped attributes) -> untyped
682
-
683
- def []: (untyped name) -> untyped
684
-
685
- def []=: (untyped name, untyped value) -> untyped
686
-
687
- def values_before_type_cast: () -> untyped
688
-
689
- def to_hash: () -> untyped
690
-
691
- def key?: (untyped name) -> untyped
692
-
693
- def keys: () -> untyped
694
-
695
- def fetch_value: (untyped name) { () -> untyped } -> untyped
696
-
697
- def write_from_database: (untyped name, untyped value) -> untyped
698
-
699
- def write_from_user: (untyped name, untyped value) -> untyped
700
-
701
- def write_cast_value: (untyped name, untyped value) -> untyped
702
-
703
- def freeze: () -> untyped
757
+ def freeze: () -> untyped
704
758
 
705
759
  def deep_dup: () -> untyped
706
760
 
@@ -722,23 +776,6 @@ module ActiveModel
722
776
  end
723
777
  end
724
778
 
725
- module ActiveModel
726
- class AttributeSet
727
- class YAMLEncoder
728
- # Attempts to do more intelligent YAML dumping of an
729
- # ActiveModel::AttributeSet to reduce the size of the resulting string
730
- # :nodoc:
731
- def initialize: (untyped default_types) -> untyped
732
-
733
- def encode: (untyped attribute_set, untyped coder) -> untyped
734
-
735
- def decode: (untyped coder) -> untyped
736
-
737
- attr_reader default_types: untyped
738
- end
739
- end
740
- end
741
-
742
779
  module ActiveModel
743
780
  module Attributes
744
781
  # nodoc:
@@ -811,26 +848,6 @@ module ActiveModel
811
848
  end
812
849
  end
813
850
 
814
- module ActiveModel
815
- class Attribute
816
- class UserProvidedDefault < FromUser
817
- # :nodoc:
818
- # :nodoc:
819
- def initialize: (untyped name, untyped value, untyped `type`, untyped database_default) -> untyped
820
-
821
- def value_before_type_cast: () -> untyped
822
-
823
- def with_type: (untyped `type`) -> untyped
824
-
825
- def marshal_dump: () -> untyped
826
-
827
- def marshal_load: (untyped values) -> untyped
828
-
829
- attr_reader user_provided_value: untyped
830
- end
831
- end
832
- end
833
-
834
851
  module ActiveModel
835
852
  # == Active \Model \Callbacks
836
853
  #
@@ -1344,6 +1361,10 @@ module ActiveModel
1344
1361
  # person.errors.include?(:age) # => false
1345
1362
  def include?: (untyped attribute) -> untyped
1346
1363
 
1364
+ alias has_key? include?
1365
+
1366
+ alias key? include?
1367
+
1347
1368
  # Delete messages for +key+. Returns the deleted messages.
1348
1369
  #
1349
1370
  # person.errors[:name] # => ["cannot be nil"]
@@ -1382,6 +1403,8 @@ module ActiveModel
1382
1403
  # person.errors.size # => 2
1383
1404
  def size: () -> untyped
1384
1405
 
1406
+ alias count size
1407
+
1385
1408
  # Returns all message values.
1386
1409
  #
1387
1410
  # person.errors.messages # => {:name=>["cannot be nil", "must be specified"]}
@@ -1401,6 +1424,8 @@ module ActiveModel
1401
1424
  # person.errors.empty? # => false
1402
1425
  def empty?: () -> untyped
1403
1426
 
1427
+ alias blank? empty?
1428
+
1404
1429
  # Returns an xml formatted representation of the Errors hash.
1405
1430
  #
1406
1431
  # person.errors.add(:name, :blank, message: "can't be blank")
@@ -1515,6 +1540,8 @@ module ActiveModel
1515
1540
  # # => ["Name is too short (minimum is 5 characters)", "Name can't be blank", "Email can't be blank"]
1516
1541
  def full_messages: () -> untyped
1517
1542
 
1543
+ alias to_a full_messages
1544
+
1518
1545
  # Returns all the full error messages for a given attribute in an array.
1519
1546
  #
1520
1547
  # class Person
@@ -1640,6 +1667,8 @@ module ActiveModel
1640
1667
 
1641
1668
  module ForbiddenAttributesProtection
1642
1669
  def sanitize_for_mass_assignment: (untyped attributes) -> untyped
1670
+
1671
+ alias sanitize_forbidden_attributes sanitize_for_mass_assignment
1643
1672
  end
1644
1673
  end
1645
1674
 
@@ -1863,6 +1892,8 @@ module ActiveModel
1863
1892
 
1864
1893
  attr_reader name: untyped
1865
1894
 
1895
+ alias cache_key collection
1896
+
1866
1897
  # Returns a new ActiveModel::Name instance. By default, the +namespace+
1867
1898
  # and +name+ option will take the namespace and name of the given class
1868
1899
  # respectively.
@@ -1987,16 +2018,6 @@ module ActiveModel
1987
2018
  end
1988
2019
  end
1989
2020
 
1990
- module ActiveModel
1991
- extend ActiveSupport::Autoload
1992
-
1993
- module Serializers
1994
- extend ActiveSupport::Autoload
1995
- end
1996
-
1997
- def self.eager_load!: () -> untyped
1998
- end
1999
-
2000
2021
  module ActiveModel
2001
2022
  module SecurePassword
2002
2023
  extend ActiveSupport::Concern
@@ -2183,6 +2204,24 @@ module ActiveModel
2183
2204
  # # => {"name" => "Napoleon", "notes" => [{"title"=>"Battle of Austerlitz"}]}
2184
2205
  def serializable_hash: (?untyped? options) -> untyped
2185
2206
 
2207
+ # Hook method defining how an attribute value should be retrieved for
2208
+ # serialization. By default this is assumed to be an instance named after
2209
+ # the attribute. Override this method in subclasses should you need to
2210
+ # retrieve the value for a given attribute differently:
2211
+ #
2212
+ # class MyClass
2213
+ # include ActiveModel::Serialization
2214
+ #
2215
+ # def initialize(data = {})
2216
+ # @data = data
2217
+ # end
2218
+ #
2219
+ # def read_attribute_for_serialization(key)
2220
+ # @data[key]
2221
+ # end
2222
+ # end
2223
+ alias read_attribute_for_serialization send
2224
+
2186
2225
  def serializable_add_includes: (?::Hash[untyped, untyped] options) { (untyped, untyped, untyped) -> untyped } -> (nil | untyped)
2187
2226
  end
2188
2227
  end
@@ -2378,6 +2417,8 @@ module ActiveModel
2378
2417
 
2379
2418
  def to_s: () -> untyped
2380
2419
 
2420
+ alias to_str to_s
2421
+
2381
2422
  def hex: () -> untyped
2382
2423
 
2383
2424
  def ==: (untyped other) -> untyped
@@ -2628,19 +2669,6 @@ module ActiveModel
2628
2669
  end
2629
2670
  end
2630
2671
 
2631
- module ActiveModel
2632
- module Type
2633
- attr_accessor registry: untyped
2634
-
2635
- # Add a new type to the registry, allowing it to be gotten through ActiveModel::Type#lookup
2636
- def self.register: (untyped type_name, ?untyped? klass, **untyped options) { () -> untyped } -> untyped
2637
-
2638
- def self.lookup: (*untyped args, **untyped kwargs) -> untyped
2639
-
2640
- def self.default_value: () -> untyped
2641
- end
2642
- end
2643
-
2644
2672
  module ActiveModel
2645
2673
  # :stopdoc:
2646
2674
  module Type
@@ -2710,7 +2738,7 @@ module ActiveModel
2710
2738
 
2711
2739
  attr_reader limit: untyped
2712
2740
 
2713
- def initialize: (?scale: untyped? scale, ?limit: untyped? limit, ?precision: untyped? precision) -> untyped
2741
+ def initialize: (?precision: untyped? precision, ?limit: untyped? limit, ?scale: untyped? scale) -> untyped
2714
2742
 
2715
2743
  def `type`: () -> nil
2716
2744
 
@@ -2776,6 +2804,8 @@ module ActiveModel
2776
2804
 
2777
2805
  def ==: (untyped other) -> untyped
2778
2806
 
2807
+ alias eql? ==
2808
+
2779
2809
  def hash: () -> untyped
2780
2810
 
2781
2811
  def assert_valid_value: () -> nil
@@ -2785,6 +2815,19 @@ module ActiveModel
2785
2815
  end
2786
2816
  end
2787
2817
 
2818
+ module ActiveModel
2819
+ module Type
2820
+ attr_accessor registry: untyped
2821
+
2822
+ # Add a new type to the registry, allowing it to be gotten through ActiveModel::Type#lookup
2823
+ def self.register: (untyped type_name, ?untyped? klass, **untyped options) { () -> untyped } -> untyped
2824
+
2825
+ def self.lookup: (*untyped args, **untyped kwargs) -> untyped
2826
+
2827
+ def self.default_value: () -> untyped
2828
+ end
2829
+ end
2830
+
2788
2831
  module ActiveModel
2789
2832
  module Validations
2790
2833
  class AbsenceValidator < EachValidator
@@ -3267,6 +3310,8 @@ module ActiveModel
3267
3310
  # +:if+, +:unless+, +:on+ and +:strict+.
3268
3311
  # See <tt>ActiveModel::Validations#validates</tt> for more information
3269
3312
  def validates_length_of: (*untyped attr_names) -> untyped
3313
+
3314
+ alias validates_size_of validates_length_of
3270
3315
  end
3271
3316
  end
3272
3317
  end
@@ -3395,357 +3440,14 @@ module ActiveModel
3395
3440
  end
3396
3441
 
3397
3442
  module ActiveModel
3398
- # == Active \Model \Validations
3399
- #
3400
- # Provides a full validation framework to your objects.
3401
- #
3402
- # A minimal implementation could be:
3403
- #
3404
- # class Person
3405
- # include ActiveModel::Validations
3406
- #
3407
- # attr_accessor :first_name, :last_name
3408
- #
3409
- # validates_each :first_name, :last_name do |record, attr, value|
3410
- # record.errors.add attr, 'starts with z.' if value.to_s[0] == ?z
3411
- # end
3412
- # end
3413
- #
3414
- # Which provides you with the full standard validation stack that you
3415
- # know from Active Record:
3416
- #
3417
- # person = Person.new
3418
- # person.valid? # => true
3419
- # person.invalid? # => false
3420
- #
3421
- # person.first_name = 'zoolander'
3422
- # person.valid? # => false
3423
- # person.invalid? # => true
3424
- # person.errors.messages # => {first_name:["starts with z."]}
3425
- #
3426
- # Note that <tt>ActiveModel::Validations</tt> automatically adds an +errors+
3427
- # method to your instances initialized with a new <tt>ActiveModel::Errors</tt>
3428
- # object, so there is no need for you to do this manually.
3429
3443
  module Validations
3430
- extend ActiveSupport::Concern
3431
-
3432
- extend ActiveModel::Naming
3433
-
3434
- extend ActiveModel::Callbacks
3435
-
3436
- extend ActiveModel::Translation
3437
-
3438
- extend HelperMethods
3439
-
3440
- include HelperMethods
3441
-
3442
- attr_accessor validation_context: untyped
3443
-
3444
3444
  module ClassMethods
3445
- # Validates each attribute against a block.
3445
+ # This method is a shortcut to all default validators and any custom
3446
+ # validator classes ending in 'Validator'. Note that Rails default
3447
+ # validators can be overridden inside specific classes by creating
3448
+ # custom validator classes in their place such as PresenceValidator.
3446
3449
  #
3447
- # class Person
3448
- # include ActiveModel::Validations
3449
- #
3450
- # attr_accessor :first_name, :last_name
3451
- #
3452
- # validates_each :first_name, :last_name, allow_blank: true do |record, attr, value|
3453
- # record.errors.add attr, 'starts with z.' if value.to_s[0] == ?z
3454
- # end
3455
- # end
3456
- #
3457
- # Options:
3458
- # * <tt>:on</tt> - Specifies the contexts where this validation is active.
3459
- # Runs in all validation contexts by default +nil+. You can pass a symbol
3460
- # or an array of symbols. (e.g. <tt>on: :create</tt> or
3461
- # <tt>on: :custom_validation_context</tt> or
3462
- # <tt>on: [:create, :custom_validation_context]</tt>)
3463
- # * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+.
3464
- # * <tt>:allow_blank</tt> - Skip validation if attribute is blank.
3465
- # * <tt>:if</tt> - Specifies a method, proc or string to call to determine
3466
- # if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
3467
- # or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
3468
- # proc or string should return or evaluate to a +true+ or +false+ value.
3469
- # * <tt>:unless</tt> - Specifies a method, proc or string to call to
3470
- # determine if the validation should not occur (e.g. <tt>unless: :skip_validation</tt>,
3471
- # or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The
3472
- # method, proc or string should return or evaluate to a +true+ or +false+
3473
- # value.
3474
- def validates_each: (*untyped attr_names) { () -> untyped } -> untyped
3475
-
3476
- VALID_OPTIONS_FOR_VALIDATE: untyped
3477
-
3478
- # Adds a validation method or block to the class. This is useful when
3479
- # overriding the +validate+ instance method becomes too unwieldy and
3480
- # you're looking for more descriptive declaration of your validations.
3481
- #
3482
- # This can be done with a symbol pointing to a method:
3483
- #
3484
- # class Comment
3485
- # include ActiveModel::Validations
3486
- #
3487
- # validate :must_be_friends
3488
- #
3489
- # def must_be_friends
3490
- # errors.add(:base, 'Must be friends to leave a comment') unless commenter.friend_of?(commentee)
3491
- # end
3492
- # end
3493
- #
3494
- # With a block which is passed with the current record to be validated:
3495
- #
3496
- # class Comment
3497
- # include ActiveModel::Validations
3498
- #
3499
- # validate do |comment|
3500
- # comment.must_be_friends
3501
- # end
3502
- #
3503
- # def must_be_friends
3504
- # errors.add(:base, 'Must be friends to leave a comment') unless commenter.friend_of?(commentee)
3505
- # end
3506
- # end
3507
- #
3508
- # Or with a block where self points to the current record to be validated:
3509
- #
3510
- # class Comment
3511
- # include ActiveModel::Validations
3512
- #
3513
- # validate do
3514
- # errors.add(:base, 'Must be friends to leave a comment') unless commenter.friend_of?(commentee)
3515
- # end
3516
- # end
3517
- #
3518
- # Note that the return value of validation methods is not relevant.
3519
- # It's not possible to halt the validate callback chain.
3520
- #
3521
- # Options:
3522
- # * <tt>:on</tt> - Specifies the contexts where this validation is active.
3523
- # Runs in all validation contexts by default +nil+. You can pass a symbol
3524
- # or an array of symbols. (e.g. <tt>on: :create</tt> or
3525
- # <tt>on: :custom_validation_context</tt> or
3526
- # <tt>on: [:create, :custom_validation_context]</tt>)
3527
- # * <tt>:if</tt> - Specifies a method, proc or string to call to determine
3528
- # if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
3529
- # or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
3530
- # proc or string should return or evaluate to a +true+ or +false+ value.
3531
- # * <tt>:unless</tt> - Specifies a method, proc or string to call to
3532
- # determine if the validation should not occur (e.g. <tt>unless: :skip_validation</tt>,
3533
- # or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The
3534
- # method, proc or string should return or evaluate to a +true+ or +false+
3535
- # value.
3536
- #
3537
- # NOTE: Calling +validate+ multiple times on the same method will overwrite previous definitions.
3538
- #
3539
- def validate: (*untyped args) { () -> untyped } -> untyped
3540
-
3541
- # List all validators that are being used to validate the model using
3542
- # +validates_with+ method.
3543
- #
3544
- # class Person
3545
- # include ActiveModel::Validations
3546
- #
3547
- # validates_with MyValidator
3548
- # validates_with OtherValidator, on: :create
3549
- # validates_with StrictValidator, strict: true
3550
- # end
3551
- #
3552
- # Person.validators
3553
- # # => [
3554
- # # #<MyValidator:0x007fbff403e808 @options={}>,
3555
- # # #<OtherValidator:0x007fbff403d930 @options={on: :create}>,
3556
- # # #<StrictValidator:0x007fbff3204a30 @options={strict:true}>
3557
- # # ]
3558
- def validators: () -> untyped
3559
-
3560
- # Clears all of the validators and validations.
3561
- #
3562
- # Note that this will clear anything that is being used to validate
3563
- # the model for both the +validates_with+ and +validate+ methods.
3564
- # It clears the validators that are created with an invocation of
3565
- # +validates_with+ and the callbacks that are set by an invocation
3566
- # of +validate+.
3567
- #
3568
- # class Person
3569
- # include ActiveModel::Validations
3570
- #
3571
- # validates_with MyValidator
3572
- # validates_with OtherValidator, on: :create
3573
- # validates_with StrictValidator, strict: true
3574
- # validate :cannot_be_robot
3575
- #
3576
- # def cannot_be_robot
3577
- # errors.add(:base, 'A person cannot be a robot') if person_is_robot
3578
- # end
3579
- # end
3580
- #
3581
- # Person.validators
3582
- # # => [
3583
- # # #<MyValidator:0x007fbff403e808 @options={}>,
3584
- # # #<OtherValidator:0x007fbff403d930 @options={on: :create}>,
3585
- # # #<StrictValidator:0x007fbff3204a30 @options={strict:true}>
3586
- # # ]
3587
- #
3588
- # If one runs <tt>Person.clear_validators!</tt> and then checks to see what
3589
- # validators this class has, you would obtain:
3590
- #
3591
- # Person.validators # => []
3592
- #
3593
- # Also, the callback set by <tt>validate :cannot_be_robot</tt> will be erased
3594
- # so that:
3595
- #
3596
- # Person._validate_callbacks.empty? # => true
3597
- #
3598
- def clear_validators!: () -> untyped
3599
-
3600
- # List all validators that are being used to validate a specific attribute.
3601
- #
3602
- # class Person
3603
- # include ActiveModel::Validations
3604
- #
3605
- # attr_accessor :name , :age
3606
- #
3607
- # validates_presence_of :name
3608
- # validates_inclusion_of :age, in: 0..99
3609
- # end
3610
- #
3611
- # Person.validators_on(:name)
3612
- # # => [
3613
- # # #<ActiveModel::Validations::PresenceValidator:0x007fe604914e60 @attributes=[:name], @options={}>,
3614
- # # ]
3615
- def validators_on: (*untyped attributes) -> untyped
3616
-
3617
- # Returns +true+ if +attribute+ is an attribute method, +false+ otherwise.
3618
- #
3619
- # class Person
3620
- # include ActiveModel::Validations
3621
- #
3622
- # attr_accessor :name
3623
- # end
3624
- #
3625
- # User.attribute_method?(:name) # => true
3626
- # User.attribute_method?(:age) # => false
3627
- def attribute_method?: (untyped attribute) -> untyped
3628
-
3629
- def inherited: (untyped base) -> untyped
3630
- end
3631
-
3632
- def initialize_dup: (untyped other) -> untyped
3633
-
3634
- # Returns the +Errors+ object that holds all information about attribute
3635
- # error messages.
3636
- #
3637
- # class Person
3638
- # include ActiveModel::Validations
3639
- #
3640
- # attr_accessor :name
3641
- # validates_presence_of :name
3642
- # end
3643
- #
3644
- # person = Person.new
3645
- # person.valid? # => false
3646
- # person.errors # => #<ActiveModel::Errors:0x007fe603816640 @messages={name:["can't be blank"]}>
3647
- def errors: () -> untyped
3648
-
3649
- # Runs all the specified validations and returns +true+ if no errors were
3650
- # added otherwise +false+.
3651
- #
3652
- # class Person
3653
- # include ActiveModel::Validations
3654
- #
3655
- # attr_accessor :name
3656
- # validates_presence_of :name
3657
- # end
3658
- #
3659
- # person = Person.new
3660
- # person.name = ''
3661
- # person.valid? # => false
3662
- # person.name = 'david'
3663
- # person.valid? # => true
3664
- #
3665
- # Context can optionally be supplied to define which callbacks to test
3666
- # against (the context is defined on the validations using <tt>:on</tt>).
3667
- #
3668
- # class Person
3669
- # include ActiveModel::Validations
3670
- #
3671
- # attr_accessor :name
3672
- # validates_presence_of :name, on: :new
3673
- # end
3674
- #
3675
- # person = Person.new
3676
- # person.valid? # => true
3677
- # person.valid?(:new) # => false
3678
- def valid?: (?untyped? context) -> untyped
3679
-
3680
- # Performs the opposite of <tt>valid?</tt>. Returns +true+ if errors were
3681
- # added, +false+ otherwise.
3682
- #
3683
- # class Person
3684
- # include ActiveModel::Validations
3685
- #
3686
- # attr_accessor :name
3687
- # validates_presence_of :name
3688
- # end
3689
- #
3690
- # person = Person.new
3691
- # person.name = ''
3692
- # person.invalid? # => true
3693
- # person.name = 'david'
3694
- # person.invalid? # => false
3695
- #
3696
- # Context can optionally be supplied to define which callbacks to test
3697
- # against (the context is defined on the validations using <tt>:on</tt>).
3698
- #
3699
- # class Person
3700
- # include ActiveModel::Validations
3701
- #
3702
- # attr_accessor :name
3703
- # validates_presence_of :name, on: :new
3704
- # end
3705
- #
3706
- # person = Person.new
3707
- # person.invalid? # => false
3708
- # person.invalid?(:new) # => true
3709
- def invalid?: (?untyped? context) -> untyped
3710
-
3711
- # Runs all the validations within the specified context. Returns +true+ if
3712
- # no errors are found, raises +ValidationError+ otherwise.
3713
- #
3714
- # Validations with no <tt>:on</tt> option will run no matter the context. Validations with
3715
- # some <tt>:on</tt> option will only run in the specified context.
3716
- def validate!: (?untyped? context) -> untyped
3717
-
3718
- def run_validations!: () -> untyped
3719
-
3720
- def raise_validation_error: () -> untyped
3721
- end
3722
-
3723
- # = Active Model ValidationError
3724
- #
3725
- # Raised by <tt>validate!</tt> when the model is invalid. Use the
3726
- # +model+ method to retrieve the record which did not validate.
3727
- #
3728
- # begin
3729
- # complex_operation_that_internally_calls_validate!
3730
- # rescue ActiveModel::ValidationError => invalid
3731
- # puts invalid.model.errors
3732
- # end
3733
- class ValidationError < StandardError
3734
- attr_reader model: untyped
3735
-
3736
- def initialize: (untyped model) -> untyped
3737
- end
3738
- end
3739
-
3740
- module ActiveModel
3741
- module Validations
3742
- module ClassMethods
3743
- # This method is a shortcut to all default validators and any custom
3744
- # validator classes ending in 'Validator'. Note that Rails default
3745
- # validators can be overridden inside specific classes by creating
3746
- # custom validator classes in their place such as PresenceValidator.
3747
- #
3748
- # Examples of using the default rails validators:
3450
+ # Examples of using the default rails validators:
3749
3451
  #
3750
3452
  # validates :terms, acceptance: true
3751
3453
  # validates :password, confirmation: true
@@ -3897,14 +3599,214 @@ module ActiveModel
3897
3599
  # end
3898
3600
  # end
3899
3601
  #
3900
- # You may also pass it multiple classes, like so:
3602
+ # You may also pass it multiple classes, like so:
3603
+ #
3604
+ # class Person
3605
+ # include ActiveModel::Validations
3606
+ # validates_with MyValidator, MyOtherValidator, on: :create
3607
+ # end
3608
+ #
3609
+ # Configuration options:
3610
+ # * <tt>:on</tt> - Specifies the contexts where this validation is active.
3611
+ # Runs in all validation contexts by default +nil+. You can pass a symbol
3612
+ # or an array of symbols. (e.g. <tt>on: :create</tt> or
3613
+ # <tt>on: :custom_validation_context</tt> or
3614
+ # <tt>on: [:create, :custom_validation_context]</tt>)
3615
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine
3616
+ # if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
3617
+ # or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>).
3618
+ # The method, proc or string should return or evaluate to a +true+ or
3619
+ # +false+ value.
3620
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to
3621
+ # determine if the validation should not occur
3622
+ # (e.g. <tt>unless: :skip_validation</tt>, or
3623
+ # <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>).
3624
+ # The method, proc or string should return or evaluate to a +true+ or
3625
+ # +false+ value.
3626
+ # * <tt>:strict</tt> - Specifies whether validation should be strict.
3627
+ # See <tt>ActiveModel::Validations#validates!</tt> for more information.
3628
+ #
3629
+ # If you pass any additional configuration options, they will be passed
3630
+ # to the class and available as +options+:
3631
+ #
3632
+ # class Person
3633
+ # include ActiveModel::Validations
3634
+ # validates_with MyValidator, my_custom_key: 'my custom value'
3635
+ # end
3636
+ #
3637
+ # class MyValidator < ActiveModel::Validator
3638
+ # def validate(record)
3639
+ # options[:my_custom_key] # => "my custom value"
3640
+ # end
3641
+ # end
3642
+ def validates_with: (*untyped args) { () -> untyped } -> untyped
3643
+ end
3644
+
3645
+ # Passes the record off to the class or classes specified and allows them
3646
+ # to add errors based on more complex conditions.
3647
+ #
3648
+ # class Person
3649
+ # include ActiveModel::Validations
3650
+ #
3651
+ # validate :instance_validations
3652
+ #
3653
+ # def instance_validations
3654
+ # validates_with MyValidator
3655
+ # end
3656
+ # end
3657
+ #
3658
+ # Please consult the class method documentation for more information on
3659
+ # creating your own validator.
3660
+ #
3661
+ # You may also pass it multiple classes, like so:
3662
+ #
3663
+ # class Person
3664
+ # include ActiveModel::Validations
3665
+ #
3666
+ # validate :instance_validations, on: :create
3667
+ #
3668
+ # def instance_validations
3669
+ # validates_with MyValidator, MyOtherValidator
3670
+ # end
3671
+ # end
3672
+ #
3673
+ # Standard configuration options (<tt>:on</tt>, <tt>:if</tt> and
3674
+ # <tt>:unless</tt>), which are available on the class version of
3675
+ # +validates_with+, should instead be placed on the +validates+ method
3676
+ # as these are applied and tested in the callback.
3677
+ #
3678
+ # If you pass any additional configuration options, they will be passed
3679
+ # to the class and available as +options+, please refer to the
3680
+ # class version of this method for more information.
3681
+ def validates_with: (*untyped args) { () -> untyped } -> untyped
3682
+ end
3683
+ end
3684
+
3685
+ module ActiveModel
3686
+ # == Active \Model \Validations
3687
+ #
3688
+ # Provides a full validation framework to your objects.
3689
+ #
3690
+ # A minimal implementation could be:
3691
+ #
3692
+ # class Person
3693
+ # include ActiveModel::Validations
3694
+ #
3695
+ # attr_accessor :first_name, :last_name
3696
+ #
3697
+ # validates_each :first_name, :last_name do |record, attr, value|
3698
+ # record.errors.add attr, 'starts with z.' if value.to_s[0] == ?z
3699
+ # end
3700
+ # end
3701
+ #
3702
+ # Which provides you with the full standard validation stack that you
3703
+ # know from Active Record:
3704
+ #
3705
+ # person = Person.new
3706
+ # person.valid? # => true
3707
+ # person.invalid? # => false
3708
+ #
3709
+ # person.first_name = 'zoolander'
3710
+ # person.valid? # => false
3711
+ # person.invalid? # => true
3712
+ # person.errors.messages # => {first_name:["starts with z."]}
3713
+ #
3714
+ # Note that <tt>ActiveModel::Validations</tt> automatically adds an +errors+
3715
+ # method to your instances initialized with a new <tt>ActiveModel::Errors</tt>
3716
+ # object, so there is no need for you to do this manually.
3717
+ module Validations
3718
+ extend ActiveSupport::Concern
3719
+
3720
+ extend ActiveModel::Naming
3721
+
3722
+ extend ActiveModel::Callbacks
3723
+
3724
+ extend ActiveModel::Translation
3725
+
3726
+ extend HelperMethods
3727
+
3728
+ include HelperMethods
3729
+
3730
+ attr_accessor validation_context: untyped
3731
+
3732
+ module ClassMethods
3733
+ # Validates each attribute against a block.
3734
+ #
3735
+ # class Person
3736
+ # include ActiveModel::Validations
3737
+ #
3738
+ # attr_accessor :first_name, :last_name
3739
+ #
3740
+ # validates_each :first_name, :last_name, allow_blank: true do |record, attr, value|
3741
+ # record.errors.add attr, 'starts with z.' if value.to_s[0] == ?z
3742
+ # end
3743
+ # end
3744
+ #
3745
+ # Options:
3746
+ # * <tt>:on</tt> - Specifies the contexts where this validation is active.
3747
+ # Runs in all validation contexts by default +nil+. You can pass a symbol
3748
+ # or an array of symbols. (e.g. <tt>on: :create</tt> or
3749
+ # <tt>on: :custom_validation_context</tt> or
3750
+ # <tt>on: [:create, :custom_validation_context]</tt>)
3751
+ # * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+.
3752
+ # * <tt>:allow_blank</tt> - Skip validation if attribute is blank.
3753
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine
3754
+ # if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
3755
+ # or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
3756
+ # proc or string should return or evaluate to a +true+ or +false+ value.
3757
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to
3758
+ # determine if the validation should not occur (e.g. <tt>unless: :skip_validation</tt>,
3759
+ # or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The
3760
+ # method, proc or string should return or evaluate to a +true+ or +false+
3761
+ # value.
3762
+ def validates_each: (*untyped attr_names) { () -> untyped } -> untyped
3763
+
3764
+ VALID_OPTIONS_FOR_VALIDATE: untyped
3765
+
3766
+ # Adds a validation method or block to the class. This is useful when
3767
+ # overriding the +validate+ instance method becomes too unwieldy and
3768
+ # you're looking for more descriptive declaration of your validations.
3769
+ #
3770
+ # This can be done with a symbol pointing to a method:
3771
+ #
3772
+ # class Comment
3773
+ # include ActiveModel::Validations
3774
+ #
3775
+ # validate :must_be_friends
3776
+ #
3777
+ # def must_be_friends
3778
+ # errors.add(:base, 'Must be friends to leave a comment') unless commenter.friend_of?(commentee)
3779
+ # end
3780
+ # end
3781
+ #
3782
+ # With a block which is passed with the current record to be validated:
3783
+ #
3784
+ # class Comment
3785
+ # include ActiveModel::Validations
3786
+ #
3787
+ # validate do |comment|
3788
+ # comment.must_be_friends
3789
+ # end
3790
+ #
3791
+ # def must_be_friends
3792
+ # errors.add(:base, 'Must be friends to leave a comment') unless commenter.friend_of?(commentee)
3793
+ # end
3794
+ # end
3795
+ #
3796
+ # Or with a block where self points to the current record to be validated:
3901
3797
  #
3902
- # class Person
3798
+ # class Comment
3903
3799
  # include ActiveModel::Validations
3904
- # validates_with MyValidator, MyOtherValidator, on: :create
3800
+ #
3801
+ # validate do
3802
+ # errors.add(:base, 'Must be friends to leave a comment') unless commenter.friend_of?(commentee)
3803
+ # end
3905
3804
  # end
3906
3805
  #
3907
- # Configuration options:
3806
+ # Note that the return value of validation methods is not relevant.
3807
+ # It's not possible to halt the validate callback chain.
3808
+ #
3809
+ # Options:
3908
3810
  # * <tt>:on</tt> - Specifies the contexts where this validation is active.
3909
3811
  # Runs in all validation contexts by default +nil+. You can pass a symbol
3910
3812
  # or an array of symbols. (e.g. <tt>on: :create</tt> or
@@ -3912,71 +3814,234 @@ module ActiveModel
3912
3814
  # <tt>on: [:create, :custom_validation_context]</tt>)
3913
3815
  # * <tt>:if</tt> - Specifies a method, proc or string to call to determine
3914
3816
  # if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
3915
- # or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>).
3916
- # The method, proc or string should return or evaluate to a +true+ or
3917
- # +false+ value.
3817
+ # or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
3818
+ # proc or string should return or evaluate to a +true+ or +false+ value.
3918
3819
  # * <tt>:unless</tt> - Specifies a method, proc or string to call to
3919
- # determine if the validation should not occur
3920
- # (e.g. <tt>unless: :skip_validation</tt>, or
3921
- # <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>).
3922
- # The method, proc or string should return or evaluate to a +true+ or
3923
- # +false+ value.
3924
- # * <tt>:strict</tt> - Specifies whether validation should be strict.
3925
- # See <tt>ActiveModel::Validations#validates!</tt> for more information.
3820
+ # determine if the validation should not occur (e.g. <tt>unless: :skip_validation</tt>,
3821
+ # or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The
3822
+ # method, proc or string should return or evaluate to a +true+ or +false+
3823
+ # value.
3926
3824
  #
3927
- # If you pass any additional configuration options, they will be passed
3928
- # to the class and available as +options+:
3825
+ # NOTE: Calling +validate+ multiple times on the same method will overwrite previous definitions.
3826
+ #
3827
+ def validate: (*untyped args) { () -> untyped } -> untyped
3828
+
3829
+ # List all validators that are being used to validate the model using
3830
+ # +validates_with+ method.
3929
3831
  #
3930
3832
  # class Person
3931
3833
  # include ActiveModel::Validations
3932
- # validates_with MyValidator, my_custom_key: 'my custom value'
3834
+ #
3835
+ # validates_with MyValidator
3836
+ # validates_with OtherValidator, on: :create
3837
+ # validates_with StrictValidator, strict: true
3933
3838
  # end
3934
3839
  #
3935
- # class MyValidator < ActiveModel::Validator
3936
- # def validate(record)
3937
- # options[:my_custom_key] # => "my custom value"
3840
+ # Person.validators
3841
+ # # => [
3842
+ # # #<MyValidator:0x007fbff403e808 @options={}>,
3843
+ # # #<OtherValidator:0x007fbff403d930 @options={on: :create}>,
3844
+ # # #<StrictValidator:0x007fbff3204a30 @options={strict:true}>
3845
+ # # ]
3846
+ def validators: () -> untyped
3847
+
3848
+ # Clears all of the validators and validations.
3849
+ #
3850
+ # Note that this will clear anything that is being used to validate
3851
+ # the model for both the +validates_with+ and +validate+ methods.
3852
+ # It clears the validators that are created with an invocation of
3853
+ # +validates_with+ and the callbacks that are set by an invocation
3854
+ # of +validate+.
3855
+ #
3856
+ # class Person
3857
+ # include ActiveModel::Validations
3858
+ #
3859
+ # validates_with MyValidator
3860
+ # validates_with OtherValidator, on: :create
3861
+ # validates_with StrictValidator, strict: true
3862
+ # validate :cannot_be_robot
3863
+ #
3864
+ # def cannot_be_robot
3865
+ # errors.add(:base, 'A person cannot be a robot') if person_is_robot
3938
3866
  # end
3939
3867
  # end
3940
- def validates_with: (*untyped args) { () -> untyped } -> untyped
3868
+ #
3869
+ # Person.validators
3870
+ # # => [
3871
+ # # #<MyValidator:0x007fbff403e808 @options={}>,
3872
+ # # #<OtherValidator:0x007fbff403d930 @options={on: :create}>,
3873
+ # # #<StrictValidator:0x007fbff3204a30 @options={strict:true}>
3874
+ # # ]
3875
+ #
3876
+ # If one runs <tt>Person.clear_validators!</tt> and then checks to see what
3877
+ # validators this class has, you would obtain:
3878
+ #
3879
+ # Person.validators # => []
3880
+ #
3881
+ # Also, the callback set by <tt>validate :cannot_be_robot</tt> will be erased
3882
+ # so that:
3883
+ #
3884
+ # Person._validate_callbacks.empty? # => true
3885
+ #
3886
+ def clear_validators!: () -> untyped
3887
+
3888
+ # List all validators that are being used to validate a specific attribute.
3889
+ #
3890
+ # class Person
3891
+ # include ActiveModel::Validations
3892
+ #
3893
+ # attr_accessor :name , :age
3894
+ #
3895
+ # validates_presence_of :name
3896
+ # validates_inclusion_of :age, in: 0..99
3897
+ # end
3898
+ #
3899
+ # Person.validators_on(:name)
3900
+ # # => [
3901
+ # # #<ActiveModel::Validations::PresenceValidator:0x007fe604914e60 @attributes=[:name], @options={}>,
3902
+ # # ]
3903
+ def validators_on: (*untyped attributes) -> untyped
3904
+
3905
+ # Returns +true+ if +attribute+ is an attribute method, +false+ otherwise.
3906
+ #
3907
+ # class Person
3908
+ # include ActiveModel::Validations
3909
+ #
3910
+ # attr_accessor :name
3911
+ # end
3912
+ #
3913
+ # User.attribute_method?(:name) # => true
3914
+ # User.attribute_method?(:age) # => false
3915
+ def attribute_method?: (untyped attribute) -> untyped
3916
+
3917
+ def inherited: (untyped base) -> untyped
3941
3918
  end
3942
3919
 
3943
- # Passes the record off to the class or classes specified and allows them
3944
- # to add errors based on more complex conditions.
3920
+ def initialize_dup: (untyped other) -> untyped
3921
+
3922
+ # Returns the +Errors+ object that holds all information about attribute
3923
+ # error messages.
3945
3924
  #
3946
3925
  # class Person
3947
3926
  # include ActiveModel::Validations
3948
3927
  #
3949
- # validate :instance_validations
3928
+ # attr_accessor :name
3929
+ # validates_presence_of :name
3930
+ # end
3950
3931
  #
3951
- # def instance_validations
3952
- # validates_with MyValidator
3953
- # end
3932
+ # person = Person.new
3933
+ # person.valid? # => false
3934
+ # person.errors # => #<ActiveModel::Errors:0x007fe603816640 @messages={name:["can't be blank"]}>
3935
+ def errors: () -> untyped
3936
+
3937
+ # Runs all the specified validations and returns +true+ if no errors were
3938
+ # added otherwise +false+.
3939
+ #
3940
+ # class Person
3941
+ # include ActiveModel::Validations
3942
+ #
3943
+ # attr_accessor :name
3944
+ # validates_presence_of :name
3954
3945
  # end
3955
3946
  #
3956
- # Please consult the class method documentation for more information on
3957
- # creating your own validator.
3947
+ # person = Person.new
3948
+ # person.name = ''
3949
+ # person.valid? # => false
3950
+ # person.name = 'david'
3951
+ # person.valid? # => true
3958
3952
  #
3959
- # You may also pass it multiple classes, like so:
3953
+ # Context can optionally be supplied to define which callbacks to test
3954
+ # against (the context is defined on the validations using <tt>:on</tt>).
3960
3955
  #
3961
3956
  # class Person
3962
3957
  # include ActiveModel::Validations
3963
3958
  #
3964
- # validate :instance_validations, on: :create
3959
+ # attr_accessor :name
3960
+ # validates_presence_of :name, on: :new
3961
+ # end
3965
3962
  #
3966
- # def instance_validations
3967
- # validates_with MyValidator, MyOtherValidator
3968
- # end
3963
+ # person = Person.new
3964
+ # person.valid? # => true
3965
+ # person.valid?(:new) # => false
3966
+ def valid?: (?untyped? context) -> untyped
3967
+
3968
+ alias validate valid?
3969
+
3970
+ # Performs the opposite of <tt>valid?</tt>. Returns +true+ if errors were
3971
+ # added, +false+ otherwise.
3972
+ #
3973
+ # class Person
3974
+ # include ActiveModel::Validations
3975
+ #
3976
+ # attr_accessor :name
3977
+ # validates_presence_of :name
3969
3978
  # end
3970
3979
  #
3971
- # Standard configuration options (<tt>:on</tt>, <tt>:if</tt> and
3972
- # <tt>:unless</tt>), which are available on the class version of
3973
- # +validates_with+, should instead be placed on the +validates+ method
3974
- # as these are applied and tested in the callback.
3980
+ # person = Person.new
3981
+ # person.name = ''
3982
+ # person.invalid? # => true
3983
+ # person.name = 'david'
3984
+ # person.invalid? # => false
3975
3985
  #
3976
- # If you pass any additional configuration options, they will be passed
3977
- # to the class and available as +options+, please refer to the
3978
- # class version of this method for more information.
3979
- def validates_with: (*untyped args) { () -> untyped } -> untyped
3986
+ # Context can optionally be supplied to define which callbacks to test
3987
+ # against (the context is defined on the validations using <tt>:on</tt>).
3988
+ #
3989
+ # class Person
3990
+ # include ActiveModel::Validations
3991
+ #
3992
+ # attr_accessor :name
3993
+ # validates_presence_of :name, on: :new
3994
+ # end
3995
+ #
3996
+ # person = Person.new
3997
+ # person.invalid? # => false
3998
+ # person.invalid?(:new) # => true
3999
+ def invalid?: (?untyped? context) -> untyped
4000
+
4001
+ # Runs all the validations within the specified context. Returns +true+ if
4002
+ # no errors are found, raises +ValidationError+ otherwise.
4003
+ #
4004
+ # Validations with no <tt>:on</tt> option will run no matter the context. Validations with
4005
+ # some <tt>:on</tt> option will only run in the specified context.
4006
+ def validate!: (?untyped? context) -> untyped
4007
+
4008
+ # Hook method defining how an attribute value should be retrieved. By default
4009
+ # this is assumed to be an instance named after the attribute. Override this
4010
+ # method in subclasses should you need to retrieve the value for a given
4011
+ # attribute differently:
4012
+ #
4013
+ # class MyClass
4014
+ # include ActiveModel::Validations
4015
+ #
4016
+ # def initialize(data = {})
4017
+ # @data = data
4018
+ # end
4019
+ #
4020
+ # def read_attribute_for_validation(key)
4021
+ # @data[key]
4022
+ # end
4023
+ # end
4024
+ alias read_attribute_for_validation send
4025
+
4026
+ def run_validations!: () -> untyped
4027
+
4028
+ def raise_validation_error: () -> untyped
4029
+ end
4030
+
4031
+ # = Active Model ValidationError
4032
+ #
4033
+ # Raised by <tt>validate!</tt> when the model is invalid. Use the
4034
+ # +model+ method to retrieve the record which did not validate.
4035
+ #
4036
+ # begin
4037
+ # complex_operation_that_internally_calls_validate!
4038
+ # rescue ActiveModel::ValidationError => invalid
4039
+ # puts invalid.model.errors
4040
+ # end
4041
+ class ValidationError < StandardError
4042
+ attr_reader model: untyped
4043
+
4044
+ def initialize: (untyped model) -> untyped
3980
4045
  end
3981
4046
  end
3982
4047
 
@@ -4137,3 +4202,13 @@ module ActiveModel
4137
4202
  # Returns the version of the currently loaded \Active \Model as a <tt>Gem::Version</tt>
4138
4203
  def self.version: () -> untyped
4139
4204
  end
4205
+
4206
+ module ActiveModel
4207
+ extend ActiveSupport::Autoload
4208
+
4209
+ module Serializers
4210
+ extend ActiveSupport::Autoload
4211
+ end
4212
+
4213
+ def self.eager_load!: () -> untyped
4214
+ end