-
Notifications
You must be signed in to change notification settings - Fork 99
/
activerecord-generated.rbs
24943 lines (19855 loc) · 870 KB
/
activerecord-generated.rbs
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
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# The generated code is based on Ruby on Rails source code
# You can find the license of Ruby on Rails from following.
#Copyright (c) 2005-2019 David Heinemeier Hansson
#
#Permission is hereby granted, free of charge, to any person obtaining
#a copy of this software and associated documentation files (the
#"Software"), to deal in the Software without restriction, including
#without limitation the rights to use, copy, modify, merge, publish,
#distribute, sublicense, and/or sell copies of the Software, and to
#permit persons to whom the Software is furnished to do so, subject to
#the following conditions:
#
#The above copyright notice and this permission notice shall be
#included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
#EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
#MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
#NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
#LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
#OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
#WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
module ActiveRecord
class AdvisoryLockBase < ActiveRecord::Base
def self._internal?: () -> ::TrueClass
end
end
module ActiveRecord
# See ActiveRecord::Aggregations::ClassMethods for documentation
module Aggregations
def initialize_dup: () -> untyped
def reload: () -> untyped
private
def clear_aggregation_cache: () -> untyped
def init_internals: () -> untyped
# Active Record implements aggregation through a macro-like class method called #composed_of
# for representing attributes as value objects. It expresses relationships like "Account [is]
# composed of Money [among other things]" or "Person [is] composed of [an] address". Each call
# to the macro adds a description of how the value objects are created from the attributes of
# the entity object (when the entity is initialized either as a new object or from finding an
# existing object) and how it can be turned back into attributes (when the entity is saved to
# the database).
#
# class Customer < ActiveRecord::Base
# composed_of :balance, class_name: "Money", mapping: %w(balance amount)
# composed_of :address, mapping: [ %w(address_street street), %w(address_city city) ]
# end
#
# The customer class now has the following methods to manipulate the value objects:
# * <tt>Customer#balance, Customer#balance=(money)</tt>
# * <tt>Customer#address, Customer#address=(address)</tt>
#
# These methods will operate with value objects like the ones described below:
#
# class Money
# include Comparable
# attr_reader :amount, :currency
# EXCHANGE_RATES = { "USD_TO_DKK" => 6 }
#
# def initialize(amount, currency = "USD")
# @amount, @currency = amount, currency
# end
#
# def exchange_to(other_currency)
# exchanged_amount = (amount * EXCHANGE_RATES["#{currency}_TO_#{other_currency}"]).floor
# Money.new(exchanged_amount, other_currency)
# end
#
# def ==(other_money)
# amount == other_money.amount && currency == other_money.currency
# end
#
# def <=>(other_money)
# if currency == other_money.currency
# amount <=> other_money.amount
# else
# amount <=> other_money.exchange_to(currency).amount
# end
# end
# end
#
# class Address
# attr_reader :street, :city
# def initialize(street, city)
# @street, @city = street, city
# end
#
# def close_to?(other_address)
# city == other_address.city
# end
#
# def ==(other_address)
# city == other_address.city && street == other_address.street
# end
# end
#
# Now it's possible to access attributes from the database through the value objects instead. If
# you choose to name the composition the same as the attribute's name, it will be the only way to
# access that attribute. That's the case with our +balance+ attribute. You interact with the value
# objects just like you would with any other attribute:
#
# customer.balance = Money.new(20) # sets the Money value object and the attribute
# customer.balance # => Money value object
# customer.balance.exchange_to("DKK") # => Money.new(120, "DKK")
# customer.balance > Money.new(10) # => true
# customer.balance == Money.new(20) # => true
# customer.balance < Money.new(5) # => false
#
# Value objects can also be composed of multiple attributes, such as the case of Address. The order
# of the mappings will determine the order of the parameters.
#
# customer.address_street = "Hyancintvej"
# customer.address_city = "Copenhagen"
# customer.address # => Address.new("Hyancintvej", "Copenhagen")
#
# customer.address = Address.new("May Street", "Chicago")
# customer.address_street # => "May Street"
# customer.address_city # => "Chicago"
#
# == Writing value objects
#
# Value objects are immutable and interchangeable objects that represent a given value, such as
# a Money object representing $5. Two Money objects both representing $5 should be equal (through
# methods such as <tt>==</tt> and <tt><=></tt> from Comparable if ranking makes sense). This is
# unlike entity objects where equality is determined by identity. An entity class such as Customer can
# easily have two different objects that both have an address on Hyancintvej. Entity identity is
# determined by object or relational unique identifiers (such as primary keys). Normal
# ActiveRecord::Base classes are entity objects.
#
# It's also important to treat the value objects as immutable. Don't allow the Money object to have
# its amount changed after creation. Create a new Money object with the new value instead. The
# <tt>Money#exchange_to</tt> method is an example of this. It returns a new value object instead of changing
# its own values. Active Record won't persist value objects that have been changed through means
# other than the writer method.
#
# The immutable requirement is enforced by Active Record by freezing any object assigned as a value
# object. Attempting to change it afterwards will result in a +RuntimeError+.
#
# Read more about value objects on http://c2.com/cgi/wiki?ValueObject and on the dangers of not
# keeping value objects immutable on http://c2.com/cgi/wiki?ValueObjectsShouldBeImmutable
#
# == Custom constructors and converters
#
# By default value objects are initialized by calling the <tt>new</tt> constructor of the value
# class passing each of the mapped attributes, in the order specified by the <tt>:mapping</tt>
# option, as arguments. If the value class doesn't support this convention then #composed_of allows
# a custom constructor to be specified.
#
# When a new value is assigned to the value object, the default assumption is that the new value
# is an instance of the value class. Specifying a custom converter allows the new value to be automatically
# converted to an instance of value class if necessary.
#
# For example, the +NetworkResource+ model has +network_address+ and +cidr_range+ attributes that should be
# aggregated using the +NetAddr::CIDR+ value class (http://www.rubydoc.info/gems/netaddr/1.5.0/NetAddr/CIDR).
# The constructor for the value class is called +create+ and it expects a CIDR address string as a parameter.
# New values can be assigned to the value object using either another +NetAddr::CIDR+ object, a string
# or an array. The <tt>:constructor</tt> and <tt>:converter</tt> options can be used to meet
# these requirements:
#
# class NetworkResource < ActiveRecord::Base
# composed_of :cidr,
# class_name: 'NetAddr::CIDR',
# mapping: [ %w(network_address network), %w(cidr_range bits) ],
# allow_nil: true,
# constructor: Proc.new { |network_address, cidr_range| NetAddr::CIDR.create("#{network_address}/#{cidr_range}") },
# converter: Proc.new { |value| NetAddr::CIDR.create(value.is_a?(Array) ? value.join('/') : value) }
# end
#
# # This calls the :constructor
# network_resource = NetworkResource.new(network_address: '192.168.0.1', cidr_range: 24)
#
# # These assignments will both use the :converter
# network_resource.cidr = [ '192.168.2.1', 8 ]
# network_resource.cidr = '192.168.0.1/24'
#
# # This assignment won't use the :converter as the value is already an instance of the value class
# network_resource.cidr = NetAddr::CIDR.create('192.168.2.1/8')
#
# # Saving and then reloading will use the :constructor on reload
# network_resource.save
# network_resource.reload
#
# == Finding records by a value object
#
# Once a #composed_of relationship is specified for a model, records can be loaded from the database
# by specifying an instance of the value object in the conditions hash. The following example
# finds all customers with +address_street+ equal to "May Street" and +address_city+ equal to "Chicago":
#
# Customer.where(address: Address.new("May Street", "Chicago"))
#
module ClassMethods
# Adds reader and writer methods for manipulating a value object:
# <tt>composed_of :address</tt> adds <tt>address</tt> and <tt>address=(new_address)</tt> methods.
#
# Options are:
# * <tt>:class_name</tt> - Specifies the class name of the association. Use it only if that name
# can't be inferred from the part id. So <tt>composed_of :address</tt> will by default be linked
# to the Address class, but if the real class name is +CompanyAddress+, you'll have to specify it
# with this option.
# * <tt>:mapping</tt> - Specifies the mapping of entity attributes to attributes of the value
# object. Each mapping is represented as an array where the first item is the name of the
# entity attribute and the second item is the name of the attribute in the value object. The
# order in which mappings are defined determines the order in which attributes are sent to the
# value class constructor.
# * <tt>:allow_nil</tt> - Specifies that the value object will not be instantiated when all mapped
# attributes are +nil+. Setting the value object to +nil+ has the effect of writing +nil+ to all
# mapped attributes.
# This defaults to +false+.
# * <tt>:constructor</tt> - A symbol specifying the name of the constructor method or a Proc that
# is called to initialize the value object. The constructor is passed all of the mapped attributes,
# in the order that they are defined in the <tt>:mapping option</tt>, as arguments and uses them
# to instantiate a <tt>:class_name</tt> object.
# The default is <tt>:new</tt>.
# * <tt>:converter</tt> - A symbol specifying the name of a class method of <tt>:class_name</tt>
# or a Proc that is called when a new value is assigned to the value object. The converter is
# passed the single value that is used in the assignment and is only called if the new value is
# not an instance of <tt>:class_name</tt>. If <tt>:allow_nil</tt> is set to true, the converter
# can return +nil+ to skip the assignment.
#
# Option examples:
# composed_of :temperature, mapping: %w(reading celsius)
# composed_of :balance, class_name: "Money", mapping: %w(balance amount)
# composed_of :address, mapping: [ %w(address_street street), %w(address_city city) ]
# composed_of :gps_location
# composed_of :gps_location, allow_nil: true
# composed_of :ip_address,
# class_name: 'IPAddr',
# mapping: %w(ip to_i),
# constructor: Proc.new { |ip| IPAddr.new(ip, Socket::AF_INET) },
# converter: Proc.new { |ip| ip.is_a?(Integer) ? IPAddr.new(ip, Socket::AF_INET) : IPAddr.new(ip.to_s) }
#
def composed_of: (untyped part_id, ?::Hash[untyped, untyped] options) -> untyped
private
def reader_method: (untyped name, untyped class_name, untyped mapping, untyped allow_nil, untyped constructor) -> untyped
def writer_method: (untyped name, untyped class_name, untyped mapping, untyped allow_nil, untyped converter) -> untyped
end
end
end
module ActiveRecord
class AssociationRelation < Relation
def initialize: (untyped klass, untyped association) -> untyped
def proxy_association: () -> untyped
def ==: (untyped other) -> untyped
def build: (?untyped? attributes) { () -> untyped } -> untyped
alias new build
def create: (?untyped? attributes) { () -> untyped } -> untyped
def create!: (?untyped? attributes) { () -> untyped } -> untyped
private
def exec_queries: () { (untyped) -> untyped } -> untyped
end
end
module ActiveRecord
module Associations
class AliasTracker
# Keeps track of table aliases for ActiveRecord::Associations::JoinDependency
# :nodoc:
def self.create: (untyped connection, untyped initial_table, untyped joins) -> untyped
def self.initial_count_for: (untyped connection, untyped name, untyped table_joins) -> untyped
# table_joins is an array of arel joins which might conflict with the aliases we assign here
def initialize: (untyped connection, untyped aliases) -> untyped
def aliased_table_for: (untyped table_name, untyped aliased_name, untyped type_caster) -> untyped
attr_reader aliases: untyped
private
def truncate: (untyped name) -> untyped
end
end
end
module ActiveRecord
module Associations
class Association
# = Active Record Associations
#
# This is the root class of all associations ('+ Foo' signifies an included module Foo):
#
# Association
# SingularAssociation
# HasOneAssociation + ForeignAssociation
# HasOneThroughAssociation + ThroughAssociation
# BelongsToAssociation
# BelongsToPolymorphicAssociation
# CollectionAssociation
# HasManyAssociation + ForeignAssociation
# HasManyThroughAssociation + ThroughAssociation
#
# Associations in Active Record are middlemen between the object that
# holds the association, known as the <tt>owner</tt>, and the associated
# result set, known as the <tt>target</tt>. Association metadata is available in
# <tt>reflection</tt>, which is an instance of <tt>ActiveRecord::Reflection::AssociationReflection</tt>.
#
# For example, given
#
# class Blog < ActiveRecord::Base
# has_many :posts
# end
#
# blog = Blog.first
#
# The association of <tt>blog.posts</tt> has the object +blog+ as its
# <tt>owner</tt>, the collection of its posts as <tt>target</tt>, and
# the <tt>reflection</tt> object represents a <tt>:has_many</tt> macro.
# nodoc:
attr_reader owner: untyped
# = Active Record Associations
#
# This is the root class of all associations ('+ Foo' signifies an included module Foo):
#
# Association
# SingularAssociation
# HasOneAssociation + ForeignAssociation
# HasOneThroughAssociation + ThroughAssociation
# BelongsToAssociation
# BelongsToPolymorphicAssociation
# CollectionAssociation
# HasManyAssociation + ForeignAssociation
# HasManyThroughAssociation + ThroughAssociation
#
# Associations in Active Record are middlemen between the object that
# holds the association, known as the <tt>owner</tt>, and the associated
# result set, known as the <tt>target</tt>. Association metadata is available in
# <tt>reflection</tt>, which is an instance of <tt>ActiveRecord::Reflection::AssociationReflection</tt>.
#
# For example, given
#
# class Blog < ActiveRecord::Base
# has_many :posts
# end
#
# blog = Blog.first
#
# The association of <tt>blog.posts</tt> has the object +blog+ as its
# <tt>owner</tt>, the collection of its posts as <tt>target</tt>, and
# the <tt>reflection</tt> object represents a <tt>:has_many</tt> macro.
# nodoc:
attr_reader target: untyped
# = Active Record Associations
#
# This is the root class of all associations ('+ Foo' signifies an included module Foo):
#
# Association
# SingularAssociation
# HasOneAssociation + ForeignAssociation
# HasOneThroughAssociation + ThroughAssociation
# BelongsToAssociation
# BelongsToPolymorphicAssociation
# CollectionAssociation
# HasManyAssociation + ForeignAssociation
# HasManyThroughAssociation + ThroughAssociation
#
# Associations in Active Record are middlemen between the object that
# holds the association, known as the <tt>owner</tt>, and the associated
# result set, known as the <tt>target</tt>. Association metadata is available in
# <tt>reflection</tt>, which is an instance of <tt>ActiveRecord::Reflection::AssociationReflection</tt>.
#
# For example, given
#
# class Blog < ActiveRecord::Base
# has_many :posts
# end
#
# blog = Blog.first
#
# The association of <tt>blog.posts</tt> has the object +blog+ as its
# <tt>owner</tt>, the collection of its posts as <tt>target</tt>, and
# the <tt>reflection</tt> object represents a <tt>:has_many</tt> macro.
# nodoc:
attr_reader reflection: untyped
def initialize: (untyped owner, untyped reflection) -> untyped
# Resets the \loaded flag to +false+ and sets the \target to +nil+.
def reset: () -> untyped
# Reloads the \target and returns +self+ on success.
# The QueryCache is cleared if +force+ is true.
def reload: (?bool force) -> untyped
# Has the \target been already \loaded?
def loaded?: () -> untyped
# Asserts the \target has been loaded setting the \loaded flag to +true+.
def loaded!: () -> untyped
# The target is stale if the target no longer points to the record(s) that the
# relevant foreign_key(s) refers to. If stale, the association accessor method
# on the owner will reload the target. It's up to subclasses to implement the
# stale_state method if relevant.
#
# Note that if the target has not been loaded, it is not considered stale.
def stale_target?: () -> untyped
# Sets the target of this association to <tt>\target</tt>, and the \loaded flag to +true+.
def target=: (untyped target) -> untyped
def scope: () -> untyped
def reset_scope: () -> untyped
# Set the inverse association, if possible
def set_inverse_instance: (untyped record) -> untyped
def set_inverse_instance_from_queries: (untyped record) -> untyped
# Remove the inverse association, if possible
def remove_inverse_instance: (untyped record) -> untyped
def inversed_from: (untyped record) -> untyped
alias inversed_from_queries inversed_from
# Returns the class of the target. belongs_to polymorphic overrides this to look at the
# polymorphic_type field on the owner.
def klass: () -> untyped
def extensions: () -> untyped
# Loads the \target if needed and returns it.
#
# This method is abstract in the sense that it relies on +find_target+,
# which is expected to be provided by descendants.
#
# If the \target is already \loaded it is just returned. Thus, you can call
# +load_target+ unconditionally to get the \target.
#
# ActiveRecord::RecordNotFound is rescued within the method, and it is
# not reraised. The proxy is \reset and +nil+ is the return value.
def load_target: () -> untyped
# We can't dump @reflection and @through_reflection since it contains the scope proc
def marshal_dump: () -> ::Array[untyped]
def marshal_load: (untyped data) -> untyped
def initialize_attributes: (untyped record, ?untyped? except_from_scope_attributes) -> untyped
def create: (?::Hash[untyped, untyped] attributes) { () -> untyped } -> untyped
def create!: (?::Hash[untyped, untyped] attributes) { () -> untyped } -> untyped
private
def find_target: () -> untyped
# The scope for this association.
#
# Note that the association_scope is merged into the target_scope only when the
# scope method is called. This is because at that point the call may be surrounded
# by scope.scoping { ... } or unscoped { ... } etc, which affects the scope which
# actually gets built.
def association_scope: () -> untyped
# Can be overridden (i.e. in ThroughAssociation) to merge in other scopes (i.e. the
# through association's scope)
def target_scope: () -> untyped
def scope_for_create: () -> untyped
def find_target?: () -> untyped
def creation_attributes: () -> untyped
# Sets the owner attributes on the given record
def set_owner_attributes: (untyped record) -> untyped
# Returns true if there is a foreign key present on the owner which
# references the target. This is used to determine whether we can load
# the target if the owner is currently a new record (and therefore
# without a key). If the owner is a new record then foreign_key must
# be present in order to load target.
#
# Currently implemented by belongs_to (vanilla and polymorphic) and
# has_one/has_many :through associations which go through a belongs_to.
def foreign_key_present?: () -> ::FalseClass
# Raises ActiveRecord::AssociationTypeMismatch unless +record+ is of
# the kind of the class of the associated objects. Meant to be used as
# a sanity check when you are about to assign an associated record.
def raise_on_type_mismatch!: (untyped record) -> untyped
def inverse_association_for: (untyped record) -> untyped
# Can be redefined by subclasses, notably polymorphic belongs_to
# The record parameter is necessary to support polymorphic inverses as we must check for
# the association in the specific class of the record.
def inverse_reflection_for: (untyped record) -> untyped
# Returns true if inverse association on the given record needs to be set.
# This method is redefined by subclasses.
def invertible_for?: (untyped record) -> untyped
# Returns true if record contains the foreign_key
def foreign_key_for?: (untyped record) -> untyped
# This should be implemented to return the values of the relevant key(s) on the owner,
# so that when stale_state is different from the value stored on the last find_target,
# the target is stale.
#
# This is only relevant to certain associations, which is why it returns +nil+ by default.
def stale_state: () -> nil
def build_record: (untyped attributes) { (untyped) -> untyped } -> untyped
# Returns true if statement cache should be skipped on the association reader.
def skip_statement_cache?: (untyped scope) -> untyped
end
end
end
module ActiveRecord
module Associations
class AssociationScope
# nodoc:
def self.scope: (untyped association) -> untyped
def self.create: () { () -> untyped } -> untyped
def initialize: (untyped value_transformation) -> untyped
INSTANCE: untyped
def scope: (untyped association) -> untyped
def self.get_bind_values: (untyped owner, untyped chain) -> untyped
private
attr_reader value_transformation: untyped
def join: (untyped table, untyped constraint) -> untyped
def last_chain_scope: (untyped scope, untyped reflection, untyped owner) -> untyped
def transform_value: (untyped value) -> untyped
def next_chain_scope: (untyped scope, untyped reflection, untyped next_reflection) -> untyped
class ReflectionProxy < SimpleDelegator
# :nodoc:
attr_reader aliased_table: untyped
def initialize: (untyped reflection, untyped aliased_table) -> untyped
def all_includes: () -> nil
end
def get_chain: (untyped reflection, untyped association, untyped tracker) -> untyped
def add_constraints: (untyped scope, untyped owner, untyped chain) -> untyped
def apply_scope: (untyped scope, untyped table, untyped key, untyped value) -> untyped
def eval_scope: (untyped reflection, untyped scope, untyped owner) -> untyped
end
end
end
module ActiveRecord
module Associations
class BelongsToAssociation < SingularAssociation
# = Active Record Belongs To Association
# nodoc:
def handle_dependency: () -> (nil | untyped)
def inversed_from: (untyped record) -> untyped
def default: () { () -> untyped } -> untyped
def reset: () -> untyped
def updated?: () -> untyped
def decrement_counters: () -> untyped
def increment_counters: () -> untyped
def decrement_counters_before_last_save: () -> untyped
def target_changed?: () -> untyped
private
def replace: (untyped record) -> untyped
def update_counters: (untyped by) -> untyped
def update_counters_via_scope: (untyped klass, untyped foreign_key, untyped by) -> untyped
def find_target?: () -> untyped
def require_counter_update?: () -> untyped
def replace_keys: (untyped record) -> untyped
def primary_key: (untyped klass) -> untyped
def foreign_key_present?: () -> untyped
# NOTE - for now, we're only supporting inverse setting from belongs_to back onto
# has_one associations.
def invertible_for?: (untyped record) -> untyped
def stale_state: () -> untyped
end
end
end
module ActiveRecord
module Associations
class BelongsToPolymorphicAssociation < BelongsToAssociation
# = Active Record Belongs To Polymorphic Association
# nodoc:
def klass: () -> untyped
def target_changed?: () -> untyped
private
def replace_keys: (untyped record) -> untyped
def inverse_reflection_for: (untyped record) -> untyped
def raise_on_type_mismatch!: (untyped record) -> nil
def stale_state: () -> untyped
end
end
end
module ActiveRecord::Associations::Builder
class Association
attr_accessor self.extensions: untyped
VALID_OPTIONS: ::Array[untyped]
def self.build: (untyped model, untyped name, untyped scope, untyped options) { () -> untyped } -> untyped
def self.create_reflection: (untyped model, untyped name, untyped scope, untyped options) { () -> untyped } -> untyped
def self.build_scope: (untyped scope) -> untyped
def self.macro: () -> untyped
def self.valid_options: (untyped options) -> untyped
def self.validate_options: (untyped options) -> untyped
def self.define_extensions: (untyped model, untyped name) -> nil
def self.define_callbacks: (untyped model, untyped reflection) -> untyped
# Defines the setter and getter methods for the association
# class Post < ActiveRecord::Base
# has_many :comments
# end
#
# Post.first.comments and Post.first.comments= methods are defined by this method...
def self.define_accessors: (untyped model, untyped reflection) -> untyped
def self.define_readers: (untyped mixin, untyped name) -> untyped
def self.define_writers: (untyped mixin, untyped name) -> untyped
def self.define_validations: (untyped model, untyped reflection) -> nil
def self.valid_dependent_options: () -> untyped
def self.check_dependent_options: (untyped dependent) -> untyped
def self.add_destroy_callbacks: (untyped model, untyped reflection) -> untyped
end
end
module ActiveRecord::Associations::Builder
class BelongsTo < SingularAssociation
# :nodoc:
# nodoc:
def self.macro: () -> :belongs_to
def self.valid_options: (untyped options) -> untyped
def self.valid_dependent_options: () -> ::Array[:destroy | :delete]
def self.define_callbacks: (untyped model, untyped reflection) -> untyped
def self.add_counter_cache_callbacks: (untyped model, untyped reflection) -> untyped
def self.touch_record: (untyped o, untyped changes, untyped foreign_key, untyped name, untyped touch, untyped touch_method) -> untyped
def self.add_touch_callbacks: (untyped model, untyped reflection) -> untyped
def self.add_default_callbacks: (untyped model, untyped reflection) -> untyped
def self.add_destroy_callbacks: (untyped model, untyped reflection) -> untyped
def self.define_validations: (untyped model, untyped reflection) -> untyped
end
end
module ActiveRecord::Associations::Builder
class CollectionAssociation < Association
# :nodoc:
# nodoc:
CALLBACKS: ::Array[untyped]
def self.valid_options: (untyped options) -> untyped
def self.define_callbacks: (untyped model, untyped reflection) -> untyped
def self.define_extensions: (untyped model, untyped name) { () -> untyped } -> untyped
def self.define_callback: (untyped model, untyped callback_name, untyped name, untyped options) -> untyped
# Defines the setter and getter methods for the collection_singular_ids.
def self.define_readers: (untyped mixin, untyped name) -> untyped
def self.define_writers: (untyped mixin, untyped name) -> untyped
end
end
module ActiveRecord::Associations::Builder
class HasAndBelongsToMany
# :nodoc:
# :nodoc:
attr_reader lhs_model: untyped
# :nodoc:
# :nodoc:
attr_reader association_name: untyped
# :nodoc:
# :nodoc:
attr_reader options: untyped
def initialize: (untyped association_name, untyped lhs_model, untyped options) -> untyped
def through_model: () -> untyped
def middle_reflection: (untyped join_model) -> untyped
private
def middle_options: (untyped join_model) -> untyped
def table_name: () -> untyped
def belongs_to_options: (untyped options) -> untyped
end
end
module ActiveRecord::Associations::Builder
class HasMany < CollectionAssociation
# :nodoc:
# nodoc:
def self.macro: () -> :has_many
def self.valid_options: (untyped options) -> untyped
def self.valid_dependent_options: () -> ::Array[:destroy | :delete_all | :nullify | :restrict_with_error | :restrict_with_exception]
end
end
module ActiveRecord::Associations::Builder
class HasOne < SingularAssociation
# :nodoc:
# nodoc:
def self.macro: () -> :has_one
def self.valid_options: (untyped options) -> untyped
def self.valid_dependent_options: () -> ::Array[:destroy | :delete | :nullify | :restrict_with_error | :restrict_with_exception]
def self.define_callbacks: (untyped model, untyped reflection) -> untyped
def self.add_destroy_callbacks: (untyped model, untyped reflection) -> untyped
def self.define_validations: (untyped model, untyped reflection) -> untyped
def self.touch_record: (untyped o, untyped name, untyped touch) -> (nil | untyped)
def self.add_touch_callbacks: (untyped model, untyped reflection) -> untyped
end
end
module ActiveRecord::Associations::Builder
class SingularAssociation < Association
# :nodoc:
# nodoc:
def self.valid_options: (untyped options) -> untyped
def self.define_accessors: (untyped model, untyped reflection) -> untyped
# Defines the (build|create)_association methods for belongs_to or has_one association
def self.define_constructors: (untyped mixin, untyped name) -> untyped
end
end
module ActiveRecord
module Associations
class CollectionAssociation < Association
# = Active Record Association Collection
#
# CollectionAssociation is an abstract class that provides common stuff to
# ease the implementation of association proxies that represent
# collections. See the class hierarchy in Association.
#
# CollectionAssociation:
# HasManyAssociation => has_many
# HasManyThroughAssociation + ThroughAssociation => has_many :through
#
# The CollectionAssociation class provides common methods to the collections
# defined by +has_and_belongs_to_many+, +has_many+ or +has_many+ with
# the +:through association+ option.
#
# You need to be careful with assumptions regarding the target: The proxy
# does not fetch records from the database until it needs them, but new
# ones created with +build+ are added to the target. So, the target may be
# non-empty and still lack children waiting to be read from the database.
# If you look directly to the database you cannot assume that's the entire
# collection because new records may have been added to the target, etc.
#
# If you need to work on all current children, new and existing records,
# +load_target+ and the +loaded+ flag are your friends.
# nodoc:
# Implements the reader method, e.g. foo.items for Foo.has_many :items
def reader: () -> untyped
# Implements the writer method, e.g. foo.items= for Foo.has_many :items
def writer: (untyped records) -> untyped
# Implements the ids reader method, e.g. foo.item_ids for Foo.has_many :items
def ids_reader: () -> untyped
# Implements the ids writer method, e.g. foo.item_ids= for Foo.has_many :items
def ids_writer: (untyped ids) -> untyped
def reset: () -> untyped
def find: (*untyped args) -> untyped
def build: (?::Hash[untyped, untyped] attributes) { () -> untyped } -> untyped
# Add +records+ to this association. Since +<<+ flattens its argument list
# and inserts each record, +push+ and +concat+ behave identically.
def concat: (*untyped records) -> untyped
# Starts a transaction in the association class's database connection.
#
# class Author < ActiveRecord::Base
# has_many :books
# end
#
# Author.first.books.transaction do
# # same effect as calling Book.transaction
# end
def transaction: (*untyped args) { () -> untyped } -> untyped
# Removes all records from the association without calling callbacks
# on the associated records. It honors the +:dependent+ option. However
# if the +:dependent+ value is +:destroy+ then in that case the +:delete_all+
# deletion strategy for the association is applied.
#
# You can force a particular deletion strategy by passing a parameter.
#
# Example:
#
# @author.books.delete_all(:nullify)
# @author.books.delete_all(:delete_all)
#
# See delete for more info.
def delete_all: (?untyped? dependent) -> untyped
# Destroy all the records from this association.
#
# See destroy for more info.
def destroy_all: () -> untyped
# Removes +records+ from this association calling +before_remove+ and
# +after_remove+ callbacks.
#
# This method is abstract in the sense that +delete_records+ has to be
# provided by descendants. Note this method does not imply the records
# are actually removed from the database, that depends precisely on
# +delete_records+. They are in any case removed from the collection.
def delete: (*untyped records) -> untyped
# Deletes the +records+ and removes them from this association calling
# +before_remove+ , +after_remove+ , +before_destroy+ and +after_destroy+ callbacks.
#
# Note that this method removes records from the database ignoring the
# +:dependent+ option.
def destroy: (*untyped records) -> untyped
# Returns the size of the collection by executing a SELECT COUNT(*)
# query if the collection hasn't been loaded, and calling
# <tt>collection.size</tt> if it has.
#
# If the collection has been already loaded +size+ and +length+ are
# equivalent. If not and you are going to need the records anyway
# +length+ will take one less query. Otherwise +size+ is more efficient.
#
# This method is abstract in the sense that it relies on
# +count_records+, which is a method descendants have to provide.
def size: () -> untyped
# Returns true if the collection is empty.
#
# If the collection has been loaded
# it is equivalent to <tt>collection.size.zero?</tt>. If the
# collection has not been loaded, it is equivalent to
# <tt>collection.exists?</tt>. If the collection has not already been
# loaded and you are going to fetch the records anyway it is better to
# check <tt>collection.length.zero?</tt>.
def empty?: () -> bool
# Replace this collection with +other_array+. This will perform a diff
# and delete/add only records that have changed.
def replace: (untyped other_array) -> untyped
def include?: (untyped record) -> untyped
def load_target: () -> untyped
def add_to_target: (untyped record, ?bool skip_callbacks) { () -> untyped } -> untyped
def scope: () -> untyped
def null_scope?: () -> untyped
def find_from_target?: () -> untyped
private
# We have some records loaded from the database (persisted) and some that are
# in-memory (memory). The same record may be represented in the persisted array
# and in the memory array.
#
# So the task of this method is to merge them according to the following rules:
#
# * The final array must not have duplicates
# * The order of the persisted array is to be preserved
# * Any changes made to attributes on objects in the memory array are to be preserved
# * Otherwise, attributes should have the value found in the database
def merge_target_lists: (untyped persisted, untyped memory) -> untyped
def _create_record: (untyped attributes, ?bool raise) { () -> untyped } -> untyped
# Do the relevant stuff to insert the given record into the association collection.
def insert_record: (untyped record, ?bool validate, ?bool raise) { () -> untyped } -> untyped
def delete_or_destroy: (untyped records, untyped method) -> (nil | untyped)
def remove_records: (untyped existing_records, untyped records, untyped method) -> (nil | untyped)
# Delete the given records from the association,
# using one of the methods +:destroy+, +:delete_all+
# or +:nullify+ (or +nil+, in which case a default is used).
def delete_records: (untyped records, untyped method) -> untyped
def replace_records: (untyped new_target, untyped original_target) -> untyped
def replace_common_records_in_memory: (untyped new_target, untyped original_target) -> untyped
def concat_records: (untyped records, ?bool raise) -> untyped
def replace_on_target: (untyped record, untyped index, untyped skip_callbacks) { (untyped) -> untyped } -> untyped
def callback: (untyped method, untyped record) -> untyped
def callbacks_for: (untyped callback_name) -> untyped
def include_in_memory?: (untyped record) -> untyped