sorbet-rails 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sorbet-rails/active_record_rbi_formatter.rb +295 -0
- data/lib/sorbet-rails/config.rb +0 -1
- data/lib/sorbet-rails/custom_types/boolean_string.rb +10 -0
- data/lib/sorbet-rails/custom_types/integer_string.rb +10 -0
- data/lib/sorbet-rails/dependent_gem_rbis/activerecord.rbi +11 -0
- data/lib/sorbet-rails/deprecation.rb +5 -0
- data/lib/sorbet-rails/model_plugins/active_record_assoc.rb +27 -6
- data/lib/sorbet-rails/model_plugins/active_record_attribute.rb +20 -8
- data/lib/sorbet-rails/model_plugins/base.rb +9 -0
- data/lib/sorbet-rails/model_plugins/enumerable_collections.rb +0 -50
- data/lib/sorbet-rails/model_plugins/plugins.rb +0 -3
- data/lib/sorbet-rails/model_rbi_formatter.rb +2 -2
- data/lib/sorbet-rails/model_utils.rb +15 -6
- data/lib/sorbet-rails/rails_mixins/custom_params_methods.rb +11 -0
- data/lib/sorbet-rails/tasks/rails_rbi.rake +20 -4
- data/sorbet-rails.gemspec +2 -2
- data/spec/active_record_rbi_formatter_spec.rb +24 -0
- data/spec/generators/rails-template.rb +88 -1
- data/spec/generators/sorbet_test_cases.rb +146 -42
- data/spec/model_rbi_formatter_spec.rb +1 -1
- data/spec/rails_helper.rb +14 -1
- data/spec/rake_rails_rbi_active_record_spec.rb +21 -0
- data/spec/rake_rails_rbi_models_spec.rb +7 -0
- data/spec/sorbet_spec.rb +12 -1
- data/spec/support/v5.0/Gemfile.lock +8 -8
- data/spec/support/v5.0/app/models/headmaster.rb +8 -0
- data/spec/support/v5.0/app/models/school.rb +2 -0
- data/spec/support/v5.0/app/models/spell.rb +5 -0
- data/spec/support/v5.0/app/models/spell_book.rb +3 -0
- data/spec/support/v5.0/app/models/subject.rb +5 -0
- data/spec/support/v5.0/app/models/wizard.rb +6 -1
- data/spec/support/v5.0/db/migrate/20190620000010_add_subject.rb +8 -0
- data/spec/support/v5.0/db/migrate/20190620000011_add_subjects_wizards.rb +8 -0
- data/spec/support/v5.0/db/migrate/20190620000012_add_spell.rb +8 -0
- data/spec/support/v5.0/db/migrate/20190620000013_add_spells_spell_books.rb +8 -0
- data/spec/support/v5.0/db/migrate/20190620000014_create_headmasters.rb +9 -0
- data/spec/support/v5.0/db/schema.rb +28 -1
- data/spec/support/v5.0/lib/mythical_rbi_plugin.rb +1 -1
- data/spec/support/v5.0/sorbet_test_cases.rb +146 -42
- data/spec/support/v5.1/Gemfile.lock +8 -8
- data/spec/support/v5.1/app/models/headmaster.rb +8 -0
- data/spec/support/v5.1/app/models/school.rb +2 -0
- data/spec/support/v5.1/app/models/spell.rb +5 -0
- data/spec/support/v5.1/app/models/spell_book.rb +3 -0
- data/spec/support/v5.1/app/models/subject.rb +5 -0
- data/spec/support/v5.1/app/models/wizard.rb +6 -1
- data/spec/support/v5.1/db/migrate/20190620000010_add_subject.rb +8 -0
- data/spec/support/v5.1/db/migrate/20190620000011_add_subjects_wizards.rb +8 -0
- data/spec/support/v5.1/db/migrate/20190620000012_add_spell.rb +8 -0
- data/spec/support/v5.1/db/migrate/20190620000013_add_spells_spell_books.rb +8 -0
- data/spec/support/v5.1/db/migrate/20190620000014_create_headmasters.rb +9 -0
- data/spec/support/v5.1/db/schema.rb +28 -1
- data/spec/support/v5.1/lib/mythical_rbi_plugin.rb +1 -1
- data/spec/support/v5.1/sorbet_test_cases.rb +146 -42
- data/spec/support/v5.2/Gemfile +1 -1
- data/spec/support/v5.2/Gemfile.lock +9 -9
- data/spec/support/v5.2/app/models/headmaster.rb +8 -0
- data/spec/support/v5.2/app/models/school.rb +2 -0
- data/spec/support/v5.2/app/models/spell.rb +5 -0
- data/spec/support/v5.2/app/models/spell_book.rb +3 -0
- data/spec/support/v5.2/app/models/subject.rb +5 -0
- data/spec/support/v5.2/app/models/wizard.rb +5 -0
- data/spec/support/v5.2/config/puma.rb +3 -0
- data/spec/support/v5.2/db/migrate/20190620000010_add_subject.rb +8 -0
- data/spec/support/v5.2/db/migrate/20190620000011_add_subjects_wizards.rb +8 -0
- data/spec/support/v5.2/db/migrate/20190620000012_add_spell.rb +8 -0
- data/spec/support/v5.2/db/migrate/20190620000013_add_spells_spell_books.rb +8 -0
- data/spec/support/v5.2/db/migrate/20190620000014_create_headmasters.rb +9 -0
- data/spec/support/v5.2/db/schema.rb +28 -1
- data/spec/support/v5.2/lib/mythical_rbi_plugin.rb +1 -1
- data/spec/support/v5.2/sorbet_test_cases.rb +146 -42
- data/spec/support/v6.0/Gemfile.lock +8 -8
- data/spec/support/v6.0/app/models/headmaster.rb +8 -0
- data/spec/support/v6.0/app/models/school.rb +2 -0
- data/spec/support/v6.0/app/models/spell.rb +5 -0
- data/spec/support/v6.0/app/models/spell_book.rb +3 -0
- data/spec/support/v6.0/app/models/subject.rb +5 -0
- data/spec/support/v6.0/app/models/wizard.rb +6 -1
- data/spec/support/v6.0/db/migrate/20190620000010_add_subject.rb +8 -0
- data/spec/support/v6.0/db/migrate/20190620000011_add_subjects_wizards.rb +8 -0
- data/spec/support/v6.0/db/migrate/20190620000012_add_spell.rb +8 -0
- data/spec/support/v6.0/db/migrate/20190620000013_add_spells_spell_books.rb +8 -0
- data/spec/support/v6.0/db/migrate/20190620000014_create_headmasters.rb +9 -0
- data/spec/support/v6.0/db/schema.rb +28 -1
- data/spec/support/v6.0/lib/mythical_rbi_plugin.rb +1 -1
- data/spec/support/v6.0/sorbet_test_cases.rb +146 -42
- data/spec/test_data/v5.0/expected_active_record_base.rbi +113 -0
- data/spec/test_data/v5.0/expected_active_record_relation.rbi +199 -0
- data/spec/test_data/v5.0/expected_habtm_subjects.rbi +660 -0
- data/spec/test_data/v5.0/expected_habtm_wizards.rbi +660 -0
- data/spec/test_data/v5.0/expected_headmaster.rbi +452 -0
- data/spec/test_data/v5.0/expected_internal_metadata.rbi +0 -217
- data/spec/test_data/v5.0/expected_potion.rbi +0 -217
- data/spec/test_data/v5.0/expected_robe.rbi +0 -217
- data/spec/test_data/v5.0/expected_schema_migration.rbi +0 -217
- data/spec/test_data/v5.0/expected_school.rbi +11 -217
- data/spec/test_data/v5.0/expected_spell.rbi +440 -0
- data/spec/test_data/v5.0/expected_spell/habtm_spell_books.rbi +443 -0
- data/spec/test_data/v5.0/expected_spell_book.rbi +14 -222
- data/spec/test_data/v5.0/expected_spell_book/habtm_spell_books.rbi +637 -0
- data/spec/test_data/v5.0/expected_spell_book/habtm_spells.rbi +443 -0
- data/spec/test_data/v5.0/expected_squib.rbi +14 -219
- data/spec/test_data/v5.0/expected_subject.rbi +440 -0
- data/spec/test_data/v5.0/expected_subject/habtm_wizards.rbi +443 -0
- data/spec/test_data/v5.0/expected_wand.rbi +4 -221
- data/spec/test_data/v5.0/expected_wizard.rbi +36 -240
- data/spec/test_data/v5.0/expected_wizard/habtm_subjects.rbi +443 -0
- data/spec/test_data/v5.0/expected_wizard_wo_spellbook.rbi +30 -240
- data/spec/test_data/v5.1/expected_active_record_base.rbi +113 -0
- data/spec/test_data/v5.1/expected_active_record_relation.rbi +178 -0
- data/spec/test_data/v5.1/expected_habtm_subjects.rbi +672 -0
- data/spec/test_data/v5.1/expected_habtm_wizards.rbi +672 -0
- data/spec/test_data/v5.1/expected_headmaster.rbi +464 -0
- data/spec/test_data/v5.1/expected_internal_metadata.rbi +0 -217
- data/spec/test_data/v5.1/expected_potion.rbi +0 -217
- data/spec/test_data/v5.1/expected_robe.rbi +0 -217
- data/spec/test_data/v5.1/expected_schema_migration.rbi +0 -217
- data/spec/test_data/v5.1/expected_school.rbi +11 -217
- data/spec/test_data/v5.1/expected_spell.rbi +452 -0
- data/spec/test_data/v5.1/expected_spell/habtm_spell_books.rbi +455 -0
- data/spec/test_data/v5.1/expected_spell_book.rbi +14 -222
- data/spec/test_data/v5.1/expected_spell_book/habtm_spell_books.rbi +649 -0
- data/spec/test_data/v5.1/expected_spell_book/habtm_spells.rbi +455 -0
- data/spec/test_data/v5.1/expected_squib.rbi +14 -219
- data/spec/test_data/v5.1/expected_subject.rbi +452 -0
- data/spec/test_data/v5.1/expected_subject/habtm_wizards.rbi +455 -0
- data/spec/test_data/v5.1/expected_wand.rbi +4 -221
- data/spec/test_data/v5.1/expected_wizard.rbi +36 -240
- data/spec/test_data/v5.1/expected_wizard/habtm_subjects.rbi +455 -0
- data/spec/test_data/v5.1/expected_wizard_wo_spellbook.rbi +30 -240
- data/spec/test_data/v5.2/expected_active_record_base.rbi +113 -0
- data/spec/test_data/v5.2/expected_active_record_relation.rbi +175 -0
- data/spec/test_data/v5.2/expected_attachment.rbi +0 -217
- data/spec/test_data/v5.2/expected_blob.rbi +3 -217
- data/spec/test_data/v5.2/expected_habtm_subjects.rbi +672 -0
- data/spec/test_data/v5.2/expected_habtm_wizards.rbi +672 -0
- data/spec/test_data/v5.2/expected_headmaster.rbi +464 -0
- data/spec/test_data/v5.2/expected_internal_metadata.rbi +0 -217
- data/spec/test_data/v5.2/expected_potion.rbi +0 -217
- data/spec/test_data/v5.2/expected_robe.rbi +0 -217
- data/spec/test_data/v5.2/expected_schema_migration.rbi +0 -217
- data/spec/test_data/v5.2/expected_school.rbi +11 -217
- data/spec/test_data/v5.2/expected_spell.rbi +452 -0
- data/spec/test_data/v5.2/expected_spell/habtm_spell_books.rbi +455 -0
- data/spec/test_data/v5.2/expected_spell_book.rbi +14 -222
- data/spec/test_data/v5.2/expected_spell_book/habtm_spell_books.rbi +649 -0
- data/spec/test_data/v5.2/expected_spell_book/habtm_spells.rbi +455 -0
- data/spec/test_data/v5.2/expected_squib.rbi +20 -219
- data/spec/test_data/v5.2/expected_subject.rbi +452 -0
- data/spec/test_data/v5.2/expected_subject/habtm_wizards.rbi +455 -0
- data/spec/test_data/v5.2/expected_wand.rbi +4 -221
- data/spec/test_data/v5.2/expected_wizard.rbi +42 -240
- data/spec/test_data/v5.2/expected_wizard/habtm_subjects.rbi +455 -0
- data/spec/test_data/v5.2/expected_wizard_wo_spellbook.rbi +36 -240
- data/spec/test_data/v6.0/expected_active_record_base.rbi +113 -0
- data/spec/test_data/v6.0/expected_active_record_relation.rbi +175 -0
- data/spec/test_data/v6.0/expected_attachment.rbi +0 -217
- data/spec/test_data/v6.0/expected_blob.rbi +3 -217
- data/spec/test_data/v6.0/expected_habtm_subjects.rbi +720 -0
- data/spec/test_data/v6.0/expected_habtm_wizards.rbi +720 -0
- data/spec/test_data/v6.0/expected_headmaster.rbi +512 -0
- data/spec/test_data/v6.0/expected_internal_metadata.rbi +0 -217
- data/spec/test_data/v6.0/expected_potion.rbi +0 -217
- data/spec/test_data/v6.0/expected_robe.rbi +0 -217
- data/spec/test_data/v6.0/expected_schema_migration.rbi +0 -217
- data/spec/test_data/v6.0/expected_school.rbi +11 -217
- data/spec/test_data/v6.0/expected_spell.rbi +500 -0
- data/spec/test_data/v6.0/expected_spell/habtm_spell_books.rbi +503 -0
- data/spec/test_data/v6.0/expected_spell_book.rbi +14 -222
- data/spec/test_data/v6.0/expected_spell_book/habtm_spell_books.rbi +697 -0
- data/spec/test_data/v6.0/expected_spell_book/habtm_spells.rbi +503 -0
- data/spec/test_data/v6.0/expected_squib.rbi +20 -219
- data/spec/test_data/v6.0/expected_subject.rbi +500 -0
- data/spec/test_data/v6.0/expected_subject/habtm_wizards.rbi +503 -0
- data/spec/test_data/v6.0/expected_wand.rbi +4 -221
- data/spec/test_data/v6.0/expected_wizard.rbi +42 -240
- data/spec/test_data/v6.0/expected_wizard/habtm_subjects.rbi +503 -0
- data/spec/test_data/v6.0/expected_wizard_wo_spellbook.rbi +36 -240
- metadata +169 -14
- data/lib/bundled_rbi/active_record_base.rbi +0 -83
- data/lib/bundled_rbi/active_record_relation.rbi +0 -122
- data/lib/sorbet-rails/model_plugins/active_record_finder_methods.rb +0 -131
- data/spec/support/v5.0/typed-override.yaml +0 -2
- data/spec/support/v5.1/typed-override.yaml +0 -2
- data/spec/support/v5.2/typed-override.yaml +0 -2
- data/spec/support/v6.0/typed-override.yaml +0 -2
@@ -1,83 +0,0 @@
|
|
1
|
-
# typed: strong
|
2
|
-
class ActiveRecord::Base
|
3
|
-
sig { params(args: T.untyped).returns(T.attached_class) }
|
4
|
-
def self.find(*args); end
|
5
|
-
|
6
|
-
sig { params(args: T.untyped).returns(T.nilable(T.attached_class)) }
|
7
|
-
def self.find_by(*args); end
|
8
|
-
|
9
|
-
sig { params(args: T.untyped).returns(T.attached_class) }
|
10
|
-
def self.find_by!(*args); end
|
11
|
-
|
12
|
-
sig {
|
13
|
-
params(
|
14
|
-
attributes: T.untyped,
|
15
|
-
block: T.nilable(T.proc.params(object: T.attached_class).void),
|
16
|
-
).
|
17
|
-
returns(T.attached_class)
|
18
|
-
}
|
19
|
-
def self.find_or_initialize_by(attributes, &block); end
|
20
|
-
|
21
|
-
sig {
|
22
|
-
params(
|
23
|
-
attributes: T.untyped,
|
24
|
-
block: T.nilable(T.proc.params(object: T.attached_class).void),
|
25
|
-
).
|
26
|
-
returns(T.attached_class)
|
27
|
-
}
|
28
|
-
def self.find_or_create_by(attributes, &block); end
|
29
|
-
|
30
|
-
sig {
|
31
|
-
params(
|
32
|
-
attributes: T.untyped,
|
33
|
-
block: T.nilable(T.proc.params(object: T.attached_class).void),
|
34
|
-
).
|
35
|
-
returns(T.attached_class)
|
36
|
-
}
|
37
|
-
def self.find_or_create_by!(attributes, &block); end
|
38
|
-
|
39
|
-
sig { returns(T.nilable(T.attached_class)) }
|
40
|
-
def self.first; end
|
41
|
-
|
42
|
-
sig { returns(T.attached_class) }
|
43
|
-
def self.first!; end
|
44
|
-
|
45
|
-
sig { returns(T.nilable(T.attached_class)) }
|
46
|
-
def self.second; end
|
47
|
-
|
48
|
-
sig { returns(T.attached_class) }
|
49
|
-
def self.second!; end
|
50
|
-
|
51
|
-
sig { returns(T.nilable(T.attached_class)) }
|
52
|
-
def self.third; end
|
53
|
-
|
54
|
-
sig { returns(T.attached_class) }
|
55
|
-
def self.third!; end
|
56
|
-
|
57
|
-
sig { returns(T.nilable(T.attached_class)) }
|
58
|
-
def self.third_to_last; end
|
59
|
-
|
60
|
-
sig { returns(T.attached_class) }
|
61
|
-
def self.third_to_last!; end
|
62
|
-
|
63
|
-
sig { returns(T.nilable(T.attached_class)) }
|
64
|
-
def self.second_to_last; end
|
65
|
-
|
66
|
-
sig { returns(T.attached_class) }
|
67
|
-
def self.second_to_last!; end
|
68
|
-
|
69
|
-
sig { returns(T.nilable(T.attached_class)) }
|
70
|
-
def self.last; end
|
71
|
-
|
72
|
-
sig { returns(T.attached_class) }
|
73
|
-
def self.last!; end
|
74
|
-
|
75
|
-
sig { params(attributes: T.untyped, block: T.untyped).returns(T.attached_class) }
|
76
|
-
def self.create(attributes = nil, &block); end
|
77
|
-
|
78
|
-
sig { params(attributes: T.untyped, block: T.untyped).returns(T.attached_class) }
|
79
|
-
def self.create!(attributes = nil, &block); end
|
80
|
-
|
81
|
-
sig { params(attributes: T.untyped, block: T.untyped).returns(T.attached_class) }
|
82
|
-
def self.new(attributes = nil, &block); end
|
83
|
-
end
|
@@ -1,122 +0,0 @@
|
|
1
|
-
# typed: strong
|
2
|
-
class ActiveRecord::Relation
|
3
|
-
Elem = type_member(fixed: T.untyped)
|
4
|
-
|
5
|
-
sig { params(args: T.untyped).returns(Elem) }
|
6
|
-
def find(*args); end
|
7
|
-
|
8
|
-
sig { params(args: T.untyped).returns(T.nilable(Elem)) }
|
9
|
-
def find_by(*args); end
|
10
|
-
|
11
|
-
sig { params(args: T.untyped).returns(Elem) }
|
12
|
-
def find_by!(*args); end
|
13
|
-
|
14
|
-
sig {
|
15
|
-
params(
|
16
|
-
attributes: T.untyped,
|
17
|
-
block: T.nilable(T.proc.params(object: Elem).void)
|
18
|
-
).
|
19
|
-
returns(Elem)
|
20
|
-
}
|
21
|
-
def find_or_initialize_by(attributes, &block); end
|
22
|
-
|
23
|
-
sig {
|
24
|
-
params(
|
25
|
-
attributes: T.untyped,
|
26
|
-
block: T.nilable(T.proc.params(object: Elem).void)
|
27
|
-
).
|
28
|
-
returns(Elem)
|
29
|
-
}
|
30
|
-
def find_or_create_by(attributes, &block); end
|
31
|
-
|
32
|
-
sig {
|
33
|
-
params(
|
34
|
-
attributes: T.untyped,
|
35
|
-
block: T.nilable(T.proc.params(object: Elem).void)
|
36
|
-
).
|
37
|
-
returns(Elem)
|
38
|
-
}
|
39
|
-
def find_or_create_by!(attributes, &block); end
|
40
|
-
|
41
|
-
sig { returns(T.nilable(Elem)) }
|
42
|
-
def first; end
|
43
|
-
|
44
|
-
sig { returns(Elem) }
|
45
|
-
def first!; end
|
46
|
-
|
47
|
-
sig { returns(T.nilable(Elem)) }
|
48
|
-
def second; end
|
49
|
-
|
50
|
-
sig { returns(Elem) }
|
51
|
-
def second!; end
|
52
|
-
|
53
|
-
sig { returns(T.nilable(Elem)) }
|
54
|
-
def third; end
|
55
|
-
|
56
|
-
sig { returns(Elem) }
|
57
|
-
def third!; end
|
58
|
-
|
59
|
-
sig { returns(T.nilable(Elem)) }
|
60
|
-
def third_to_last; end
|
61
|
-
|
62
|
-
sig { returns(Elem) }
|
63
|
-
def third_to_last!; end
|
64
|
-
|
65
|
-
sig { returns(T.nilable(Elem)) }
|
66
|
-
def second_to_last; end
|
67
|
-
|
68
|
-
sig { returns(Elem) }
|
69
|
-
def second_to_last!; end
|
70
|
-
|
71
|
-
sig { returns(T.nilable(Elem)) }
|
72
|
-
def last; end
|
73
|
-
|
74
|
-
sig { returns(Elem) }
|
75
|
-
def last!; end
|
76
|
-
|
77
|
-
sig do
|
78
|
-
override.params(
|
79
|
-
start: T.nilable(Integer),
|
80
|
-
finish: T.nilable(Integer),
|
81
|
-
batch_size: T.nilable(Integer),
|
82
|
-
error_on_ignore: T.nilable(T::Boolean),
|
83
|
-
block: T.nilable(T.proc.params(e: Elem).void) # block is optional, eg. you can do Klass.find_each.map
|
84
|
-
).returns(T::Array[Elem])
|
85
|
-
end
|
86
|
-
def find_each(start: nil, finish: nil, batch_size: 1000, error_on_ignore: nil, &block); end
|
87
|
-
|
88
|
-
sig { override.params(block: T.proc.params(e: Elem).void).returns(T::Array[Elem]) }
|
89
|
-
def each(&block); end
|
90
|
-
|
91
|
-
sig { params(level: T.nilable(Integer)).returns(T::Array[Elem]) }
|
92
|
-
def flatten(level); end
|
93
|
-
|
94
|
-
sig { returns(T::Array[Elem]) }
|
95
|
-
def to_a; end
|
96
|
-
|
97
|
-
sig do
|
98
|
-
type_parameters(:U).params(
|
99
|
-
blk: T.proc.params(arg0: Elem).returns(T.type_parameter(:U)),
|
100
|
-
)
|
101
|
-
.returns(T::Array[T.type_parameter(:U)])
|
102
|
-
end
|
103
|
-
def map(&blk); end
|
104
|
-
|
105
|
-
sig { params(conditions: T.untyped).returns(T::Boolean) }
|
106
|
-
def exists?(conditions = nil); end
|
107
|
-
|
108
|
-
sig { returns(T::Boolean) }
|
109
|
-
def any?; end
|
110
|
-
|
111
|
-
sig { returns(T::Boolean) }
|
112
|
-
def empty?; end
|
113
|
-
|
114
|
-
sig { returns(T::Boolean) }
|
115
|
-
def many?; end
|
116
|
-
|
117
|
-
sig { returns(T::Boolean) }
|
118
|
-
def none?; end
|
119
|
-
|
120
|
-
sig { returns(T::Boolean) }
|
121
|
-
def one?; end
|
122
|
-
end
|
@@ -1,131 +0,0 @@
|
|
1
|
-
# typed: strict
|
2
|
-
require ('sorbet-rails/model_plugins/base')
|
3
|
-
class SorbetRails::ModelPlugins::ActiveRecordFinderMethods < SorbetRails::ModelPlugins::Base
|
4
|
-
|
5
|
-
sig { override.params(root: Parlour::RbiGenerator::Namespace).void }
|
6
|
-
def generate(root)
|
7
|
-
model_class_rbi = root.create_class(self.model_class_name)
|
8
|
-
create_finder_methods_for(model_class_rbi, class_method: true, include_methods_that_return_self: false)
|
9
|
-
|
10
|
-
model_relation_class_rbi = root.create_class(self.model_relation_class_name)
|
11
|
-
create_finder_methods_for(model_relation_class_rbi, class_method: false, include_methods_that_return_self: false)
|
12
|
-
|
13
|
-
model_assoc_proxy_class_rbi = root.create_class(self.model_assoc_proxy_class_name)
|
14
|
-
create_finder_methods_for(model_assoc_proxy_class_rbi, class_method: false)
|
15
|
-
|
16
|
-
model_assoc_relation_rbi = root.create_class(self.model_assoc_relation_class_name)
|
17
|
-
create_finder_methods_for(model_assoc_relation_rbi, class_method: false)
|
18
|
-
end
|
19
|
-
|
20
|
-
sig do
|
21
|
-
params(
|
22
|
-
class_rbi: Parlour::RbiGenerator::ClassNamespace,
|
23
|
-
class_method: T::Boolean,
|
24
|
-
include_methods_that_return_self: T::Boolean
|
25
|
-
).void
|
26
|
-
end
|
27
|
-
def create_finder_methods_for(class_rbi, class_method:, include_methods_that_return_self: true)
|
28
|
-
# The intent of this is to prevent these methods from being generated
|
29
|
-
# unnecessarily when T.attached_class or Elem can be used to reduce
|
30
|
-
# the number of method signatures that have to be generated.
|
31
|
-
if include_methods_that_return_self
|
32
|
-
class_rbi.create_method(
|
33
|
-
"find",
|
34
|
-
parameters: [ Parameter.new("*args", type: "T.untyped") ],
|
35
|
-
return_type: self.model_class_name,
|
36
|
-
class_method: class_method,
|
37
|
-
)
|
38
|
-
class_rbi.create_method(
|
39
|
-
"find_by",
|
40
|
-
parameters: [ Parameter.new("*args", type: "T.untyped") ],
|
41
|
-
return_type: "T.nilable(#{self.model_class_name})",
|
42
|
-
class_method: class_method,
|
43
|
-
)
|
44
|
-
class_rbi.create_method(
|
45
|
-
"find_by!",
|
46
|
-
parameters: [ Parameter.new("*args", type: "T.untyped") ],
|
47
|
-
return_type: self.model_class_name,
|
48
|
-
class_method: class_method
|
49
|
-
)
|
50
|
-
class_rbi.create_method(
|
51
|
-
"find_or_initialize_by",
|
52
|
-
parameters: [
|
53
|
-
Parameter.new("attributes", type: "T.untyped") ,
|
54
|
-
Parameter.new(
|
55
|
-
"&block",
|
56
|
-
type: "T.nilable(T.proc.params(object: #{self.model_class_name}).void)",
|
57
|
-
),
|
58
|
-
],
|
59
|
-
return_type: self.model_class_name,
|
60
|
-
class_method: class_method
|
61
|
-
)
|
62
|
-
class_rbi.create_method(
|
63
|
-
"find_or_create_by",
|
64
|
-
parameters: [
|
65
|
-
Parameter.new("attributes", type: "T.untyped") ,
|
66
|
-
Parameter.new(
|
67
|
-
"&block",
|
68
|
-
type: "T.nilable(T.proc.params(object: #{self.model_class_name}).void)"
|
69
|
-
),
|
70
|
-
],
|
71
|
-
return_type: self.model_class_name,
|
72
|
-
class_method: class_method
|
73
|
-
)
|
74
|
-
class_rbi.create_method(
|
75
|
-
"find_or_create_by!",
|
76
|
-
parameters: [
|
77
|
-
Parameter.new("attributes", type: "T.untyped") ,
|
78
|
-
Parameter.new(
|
79
|
-
"&block",
|
80
|
-
type: "T.nilable(T.proc.params(object: #{self.model_class_name}).void)",
|
81
|
-
),
|
82
|
-
],
|
83
|
-
return_type: self.model_class_name,
|
84
|
-
class_method: class_method
|
85
|
-
)
|
86
|
-
|
87
|
-
["first", "second", "third", "third_to_last", "second_to_last", "last"].
|
88
|
-
each do |method_name|
|
89
|
-
create_finder_method_pair(class_rbi, method_name, class_method)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
# Checker methods
|
94
|
-
class_rbi.create_method(
|
95
|
-
"exists?",
|
96
|
-
parameters: [ Parameter.new("conditions", type: "T.untyped", default: "nil") ],
|
97
|
-
return_type: "T::Boolean",
|
98
|
-
class_method: class_method,
|
99
|
-
)
|
100
|
-
|
101
|
-
["any?", "many?", "none?", "one?", "empty?"].each do |method_name|
|
102
|
-
class_rbi.create_method(
|
103
|
-
method_name,
|
104
|
-
parameters: [ Parameter.new("*args", type: "T.untyped") ],
|
105
|
-
return_type: "T::Boolean",
|
106
|
-
class_method: class_method,
|
107
|
-
)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
sig {
|
112
|
-
params(
|
113
|
-
class_rbi: Parlour::RbiGenerator::ClassNamespace,
|
114
|
-
method_name: String,
|
115
|
-
class_method: T::Boolean,
|
116
|
-
).
|
117
|
-
void
|
118
|
-
}
|
119
|
-
def create_finder_method_pair(class_rbi, method_name, class_method)
|
120
|
-
class_rbi.create_method(
|
121
|
-
method_name,
|
122
|
-
return_type: "T.nilable(#{self.model_class_name})",
|
123
|
-
class_method: class_method,
|
124
|
-
)
|
125
|
-
class_rbi.create_method(
|
126
|
-
"#{method_name}!",
|
127
|
-
return_type: self.model_class_name,
|
128
|
-
class_method: class_method,
|
129
|
-
)
|
130
|
-
end
|
131
|
-
end
|