tapioca 0.17.9 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -2
  3. data/lib/tapioca/bundler_ext/auto_require_hook.rb +0 -3
  4. data/lib/tapioca/cli.rb +0 -2
  5. data/lib/tapioca/commands/abstract_dsl.rb +21 -2
  6. data/lib/tapioca/commands/abstract_gem.rb +20 -1
  7. data/lib/tapioca/commands/annotations.rb +7 -3
  8. data/lib/tapioca/commands/check_shims.rb +9 -2
  9. data/lib/tapioca/commands/command.rb +0 -1
  10. data/lib/tapioca/dsl/compiler.rb +17 -16
  11. data/lib/tapioca/dsl/compilers/aasm.rb +2 -6
  12. data/lib/tapioca/dsl/compilers/action_controller_helpers.rb +2 -6
  13. data/lib/tapioca/dsl/compilers/action_mailer.rb +1 -5
  14. data/lib/tapioca/dsl/compilers/action_text.rb +1 -5
  15. data/lib/tapioca/dsl/compilers/active_job.rb +1 -5
  16. data/lib/tapioca/dsl/compilers/active_model_attributes.rb +1 -5
  17. data/lib/tapioca/dsl/compilers/active_model_secure_password.rb +1 -5
  18. data/lib/tapioca/dsl/compilers/active_model_validations_confirmation.rb +1 -3
  19. data/lib/tapioca/dsl/compilers/active_record_associations.rb +1 -6
  20. data/lib/tapioca/dsl/compilers/active_record_columns.rb +8 -5
  21. data/lib/tapioca/dsl/compilers/active_record_delegated_types.rb +1 -4
  22. data/lib/tapioca/dsl/compilers/active_record_enum.rb +1 -5
  23. data/lib/tapioca/dsl/compilers/active_record_fixtures.rb +1 -5
  24. data/lib/tapioca/dsl/compilers/active_record_relations.rb +45 -87
  25. data/lib/tapioca/dsl/compilers/active_record_scope.rb +1 -2
  26. data/lib/tapioca/dsl/compilers/active_record_secure_token.rb +1 -4
  27. data/lib/tapioca/dsl/compilers/active_record_store.rb +1 -4
  28. data/lib/tapioca/dsl/compilers/active_record_typed_store.rb +1 -5
  29. data/lib/tapioca/dsl/compilers/active_resource.rb +1 -5
  30. data/lib/tapioca/dsl/compilers/active_storage.rb +2 -6
  31. data/lib/tapioca/dsl/compilers/active_support_concern.rb +6 -10
  32. data/lib/tapioca/dsl/compilers/active_support_current_attributes.rb +4 -19
  33. data/lib/tapioca/dsl/compilers/active_support_environment_inquirer.rb +60 -0
  34. data/lib/tapioca/dsl/compilers/active_support_time_ext.rb +1 -5
  35. data/lib/tapioca/dsl/compilers/config.rb +2 -6
  36. data/lib/tapioca/dsl/compilers/frozen_record.rb +1 -5
  37. data/lib/tapioca/dsl/compilers/graphql_input_object.rb +1 -5
  38. data/lib/tapioca/dsl/compilers/graphql_mutation.rb +1 -5
  39. data/lib/tapioca/dsl/compilers/identity_cache.rb +2 -6
  40. data/lib/tapioca/dsl/compilers/json_api_client_resource.rb +4 -18
  41. data/lib/tapioca/dsl/compilers/kredis.rb +1 -5
  42. data/lib/tapioca/dsl/compilers/mixed_in_class_attributes.rb +2 -6
  43. data/lib/tapioca/dsl/compilers/protobuf.rb +2 -6
  44. data/lib/tapioca/dsl/compilers/rails_generators.rb +1 -5
  45. data/lib/tapioca/dsl/compilers/sidekiq_worker.rb +1 -5
  46. data/lib/tapioca/dsl/compilers/smart_properties.rb +1 -5
  47. data/lib/tapioca/dsl/compilers/state_machines.rb +2 -6
  48. data/lib/tapioca/dsl/compilers/url_helpers.rb +7 -10
  49. data/lib/tapioca/dsl/helpers/active_model_type_helper.rb +0 -2
  50. data/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb +3 -6
  51. data/lib/tapioca/dsl/helpers/active_record_constants_helper.rb +0 -2
  52. data/lib/tapioca/dsl/helpers/graphql_type_helper.rb +18 -5
  53. data/lib/tapioca/dsl/pipeline.rb +25 -13
  54. data/lib/tapioca/executor.rb +0 -2
  55. data/lib/tapioca/gem/events.rb +15 -23
  56. data/lib/tapioca/gem/listeners/base.rb +0 -1
  57. data/lib/tapioca/gem/listeners/dynamic_mixins.rb +0 -2
  58. data/lib/tapioca/gem/listeners/foreign_constants.rb +0 -2
  59. data/lib/tapioca/gem/listeners/methods.rb +19 -9
  60. data/lib/tapioca/gem/listeners/mixins.rb +3 -5
  61. data/lib/tapioca/gem/listeners/remove_empty_payload_scopes.rb +0 -2
  62. data/lib/tapioca/gem/listeners/sorbet_enums.rb +0 -2
  63. data/lib/tapioca/gem/listeners/sorbet_helpers.rb +0 -2
  64. data/lib/tapioca/gem/listeners/sorbet_props.rb +0 -1
  65. data/lib/tapioca/gem/listeners/sorbet_required_ancestors.rb +0 -2
  66. data/lib/tapioca/gem/listeners/sorbet_signatures.rb +0 -2
  67. data/lib/tapioca/gem/listeners/sorbet_type_variables.rb +1 -3
  68. data/lib/tapioca/gem/listeners/source_location.rb +6 -7
  69. data/lib/tapioca/gem/listeners/subconstants.rb +0 -2
  70. data/lib/tapioca/gem/listeners/yard_doc.rb +0 -2
  71. data/lib/tapioca/gem/pipeline.rb +25 -21
  72. data/lib/tapioca/gemfile.rb +1 -3
  73. data/lib/tapioca/helpers/cli_helper.rb +0 -1
  74. data/lib/tapioca/helpers/config_helper.rb +5 -2
  75. data/lib/tapioca/helpers/env_helper.rb +0 -1
  76. data/lib/tapioca/helpers/gem_helper.rb +0 -2
  77. data/lib/tapioca/helpers/git_attributes.rb +0 -2
  78. data/lib/tapioca/helpers/package_url.rb +416 -0
  79. data/lib/tapioca/helpers/rbi_files_helper.rb +8 -2
  80. data/lib/tapioca/helpers/rbi_helper.rb +0 -3
  81. data/lib/tapioca/helpers/sorbet_helper.rb +0 -2
  82. data/lib/tapioca/helpers/test/content.rb +0 -1
  83. data/lib/tapioca/helpers/test/dsl_compiler.rb +0 -3
  84. data/lib/tapioca/helpers/test/isolation.rb +0 -6
  85. data/lib/tapioca/helpers/test/template.rb +1 -9
  86. data/lib/tapioca/internal.rb +1 -1
  87. data/lib/tapioca/loaders/dsl.rb +0 -4
  88. data/lib/tapioca/loaders/gem.rb +14 -6
  89. data/lib/tapioca/loaders/loader.rb +0 -1
  90. data/lib/tapioca/rbi_ext/model.rb +9 -4
  91. data/lib/tapioca/rbi_formatter.rb +0 -2
  92. data/lib/tapioca/repo_index.rb +1 -4
  93. data/lib/tapioca/runtime/dynamic_mixin_compiler.rb +6 -9
  94. data/lib/tapioca/runtime/generic_type_registry.rb +8 -12
  95. data/lib/tapioca/runtime/reflection.rb +25 -31
  96. data/lib/tapioca/runtime/trackers/autoload.rb +0 -3
  97. data/lib/tapioca/runtime/trackers/constant_definition.rb +30 -8
  98. data/lib/tapioca/runtime/trackers/method_definition.rb +4 -5
  99. data/lib/tapioca/runtime/trackers/mixin.rb +5 -8
  100. data/lib/tapioca/runtime/trackers/required_ancestor.rb +2 -4
  101. data/lib/tapioca/runtime/trackers/tracker.rb +1 -4
  102. data/lib/tapioca/runtime/trackers.rb +0 -4
  103. data/lib/tapioca/sorbet_ext/generic_name_patch.rb +1 -3
  104. data/lib/tapioca/static/requires_compiler.rb +1 -3
  105. data/lib/tapioca/static/symbol_loader.rb +0 -1
  106. data/lib/tapioca/static/symbol_table_parser.rb +0 -4
  107. data/lib/tapioca/version.rb +1 -1
  108. data/lib/tapioca.rb +0 -2
  109. metadata +18 -5
  110. data/lib/tapioca/helpers/source_uri.rb +0 -84
  111. data/lib/tapioca/runtime/attached_class_of_32.rb +0 -20
  112. data/lib/tapioca/runtime/attached_class_of_legacy.rb +0 -24
@@ -151,7 +151,6 @@ module Tapioca
151
151
  # ~~~
152
152
  #: [ConstantType = singleton(::ActiveRecord::Base)]
153
153
  class ActiveRecordRelations < Compiler
154
- extend T::Sig
155
154
  include Helpers::ActiveRecordConstantsHelper
156
155
  include SorbetHelper
157
156
 
@@ -181,10 +180,8 @@ module Tapioca
181
180
  end
182
181
 
183
182
  class << self
184
- extend T::Sig
185
-
186
183
  # @override
187
- #: -> T::Enumerable[Module]
184
+ #: -> Enumerable[T::Module[top]]
188
185
  def gather_constants
189
186
  ActiveRecord::Base.descendants.reject(&:abstract_class?)
190
187
  end
@@ -224,7 +221,7 @@ module Tapioca
224
221
  batch_size: ["Integer", "1000"],
225
222
  of: ["Integer", "1000"],
226
223
  error_on_ignore: ["T.untyped", "nil"],
227
- order: ["Symbol", ":asc"],
224
+ order: ["T.any(Symbol, T::Array[Symbol])", ":asc"],
228
225
  cursor: ["T.untyped", "primary_key"],
229
226
  use_ranges: ["T.untyped", "nil"],
230
227
  } #: Hash[Symbol, [String, String]]
@@ -541,6 +538,7 @@ module Tapioca
541
538
  #: -> void
542
539
  def create_relation_methods
543
540
  create_relation_method("all")
541
+ create_unscoped_relation_method
544
542
 
545
543
  QUERY_METHODS.each do |method_name|
546
544
  case method_name
@@ -604,47 +602,9 @@ module Tapioca
604
602
 
605
603
  #: -> void
606
604
  def create_association_relation_methods
607
- returning_type = "T.nilable(T.any(T::Array[Symbol], FalseClass))"
608
- unique_by_type = "T.nilable(T.any(T::Array[Symbol], Symbol))"
609
-
610
- ASSOCIATION_METHODS.each do |method_name|
611
- case method_name
612
- when :insert_all, :insert_all!, :upsert_all
613
- parameters = [
614
- create_param("attributes", type: "T::Array[Hash]"),
615
- create_kw_opt_param("returning", type: returning_type, default: "nil"),
616
- ]
617
-
618
- # Bang methods don't have the `unique_by` parameter
619
- unless bang_method?(method_name)
620
- parameters << create_kw_opt_param("unique_by", type: unique_by_type, default: "nil")
621
- end
622
-
623
- association_relation_methods_module.create_method(
624
- method_name.to_s,
625
- parameters: parameters,
626
- return_type: "ActiveRecord::Result",
627
- )
628
- when :insert, :insert!, :upsert
629
- parameters = [
630
- create_param("attributes", type: "Hash"),
631
- create_kw_opt_param("returning", type: returning_type, default: "nil"),
632
- ]
633
-
634
- # Bang methods don't have the `unique_by` parameter
635
- unless bang_method?(method_name)
636
- parameters << create_kw_opt_param("unique_by", type: unique_by_type, default: "nil")
637
- end
638
-
639
- association_relation_methods_module.create_method(
640
- method_name.to_s,
641
- parameters: parameters,
642
- return_type: "ActiveRecord::Result",
643
- )
644
- when :proxy_association
645
- # skip - private method
646
- end
647
- end
605
+ # skips insert/upsert methods - these methods' signatures aren't model-specific and don't need to be generated dynamically
606
+ # also skips proxy_association method - it's a private method
607
+ # but there could be other association methods that we need to generate
648
608
  end
649
609
 
650
610
  #: -> void
@@ -953,44 +913,8 @@ module Tapioca
953
913
  sig.return_type = constant_name
954
914
  end
955
915
  end
956
- when :insert_all, :insert_all!, :upsert_all # insert all methods
957
- returning_type = "T.nilable(T.any(T::Array[Symbol], FalseClass))"
958
- unique_by_type = "T.nilable(T.any(T::Array[Symbol], Symbol))"
959
-
960
- parameters = [
961
- create_param("attributes", type: "T::Array[Hash]"),
962
- create_kw_opt_param("returning", type: returning_type, default: "nil"),
963
- ]
964
-
965
- # Bang methods don't have the `unique_by` parameter
966
- unless bang_method?(method_name)
967
- parameters << create_kw_opt_param("unique_by", type: unique_by_type, default: "nil")
968
- end
969
-
970
- common_relation_methods_module.create_method(
971
- method_name.to_s,
972
- parameters: parameters,
973
- return_type: "ActiveRecord::Result",
974
- )
975
- when :insert, :insert!, :upsert # insert methods
976
- returning_type = "T.nilable(T.any(T::Array[Symbol], FalseClass))"
977
- unique_by_type = "T.nilable(T.any(T::Array[Symbol], Symbol))"
978
-
979
- parameters = [
980
- create_param("attributes", type: "Hash"),
981
- create_kw_opt_param("returning", type: returning_type, default: "nil"),
982
- ]
983
-
984
- # Bang methods don't have the `unique_by` parameter
985
- unless bang_method?(method_name)
986
- parameters << create_kw_opt_param("unique_by", type: unique_by_type, default: "nil")
987
- end
988
-
989
- common_relation_methods_module.create_method(
990
- method_name.to_s,
991
- parameters: parameters,
992
- return_type: "ActiveRecord::Result",
993
- )
916
+ when :insert_all, :insert_all!, :upsert_all, :insert, :insert!, :upsert # insert methods
917
+ # skip - these methods' signatures aren't model-specific and don't need to be generated dynamically
994
918
  when :delete, :destroy
995
919
  # For these cases, it is valid to pass the above kind of things, but also:
996
920
  # - a model identifier, which can be:
@@ -1021,7 +945,7 @@ module Tapioca
1021
945
  common_relation_methods_module.create_method(
1022
946
  method_name.to_s,
1023
947
  parameters: [
1024
- create_param("args", type: "T.untyped"),
948
+ create_rest_param("args", type: "T.untyped"),
1025
949
  ],
1026
950
  return_type: method_name == :delete_by ? "Integer" : "T::Array[#{constant_name}]",
1027
951
  )
@@ -1050,7 +974,7 @@ module Tapioca
1050
974
  when :find_each
1051
975
  [constant_name, "T::Enumerator[#{constant_name}]"]
1052
976
  when :find_in_batches
1053
- ["T::Array[#{constant_name}]", "T::Enumerator[T::Enumerator[#{constant_name}]]"]
977
+ ["T::Array[#{constant_name}]", "T::Enumerator[T::Array[#{constant_name}]]"]
1054
978
  when :in_batches
1055
979
  [RelationClassName, "::ActiveRecord::Batches::BatchEnumerator"]
1056
980
  else
@@ -1107,7 +1031,12 @@ module Tapioca
1107
1031
  end
1108
1032
  end
1109
1033
 
1110
- #: ((Symbol | String) name, ?parameters: Array[RBI::TypedParam], ?relation_return_type: String, ?association_return_type: String) -> void
1034
+ #: (
1035
+ #| (Symbol | String) name,
1036
+ #| ?parameters: Array[RBI::TypedParam],
1037
+ #| ?relation_return_type: String,
1038
+ #| ?association_return_type: String
1039
+ #| ) -> void
1111
1040
  def create_relation_method(
1112
1041
  name,
1113
1042
  parameters: [],
@@ -1125,6 +1054,35 @@ module Tapioca
1125
1054
  return_type: association_return_type,
1126
1055
  )
1127
1056
  end
1057
+
1058
+ #: -> void
1059
+ def create_unscoped_relation_method
1060
+ relation_methods_module.create_method("unscoped") do |method|
1061
+ method.add_block_param("block")
1062
+
1063
+ method.add_sig do |sig|
1064
+ sig.return_type = RelationClassName
1065
+ end
1066
+
1067
+ method.add_sig(type_params: ["U"]) do |sig|
1068
+ sig.add_param("block", "T.proc.returns(T.type_parameter(:U))")
1069
+ sig.return_type = "T.type_parameter(:U)"
1070
+ end
1071
+ end
1072
+
1073
+ association_relation_methods_module.create_method("unscoped") do |method|
1074
+ method.add_block_param("block")
1075
+
1076
+ method.add_sig do |sig|
1077
+ sig.return_type = AssociationRelationClassName
1078
+ end
1079
+
1080
+ method.add_sig(type_params: ["U"]) do |sig|
1081
+ sig.add_param("block", "T.proc.returns(T.type_parameter(:U))")
1082
+ sig.return_type = "T.type_parameter(:U)"
1083
+ end
1084
+ end
1085
+ end
1128
1086
  end
1129
1087
  end
1130
1088
  end
@@ -40,7 +40,6 @@ module Tapioca
40
40
  # ~~~
41
41
  #: [ConstantType = singleton(::ActiveRecord::Base)]
42
42
  class ActiveRecordScope < Compiler
43
- extend T::Sig
44
43
  include Helpers::ActiveRecordConstantsHelper
45
44
 
46
45
  # @override
@@ -78,7 +77,7 @@ module Tapioca
78
77
 
79
78
  class << self
80
79
  # @override
81
- #: -> T::Enumerable[Module]
80
+ #: -> Enumerable[T::Module[top]]
82
81
  def gather_constants
83
82
  descendants_of(::ActiveRecord::Base).reject(&:abstract_class?)
84
83
  end
@@ -34,7 +34,6 @@ module Tapioca
34
34
  # ~~~
35
35
  #: [ConstantType = (singleton(ActiveRecord::Base) & Extensions::ActiveRecord)]
36
36
  class ActiveRecordSecureToken < Compiler
37
- extend T::Sig
38
37
  include Helpers::ActiveRecordConstantsHelper
39
38
 
40
39
  # @override
@@ -57,10 +56,8 @@ module Tapioca
57
56
  end
58
57
 
59
58
  class << self
60
- extend T::Sig
61
-
62
59
  # @override
63
- #: -> T::Enumerable[Module]
60
+ #: -> Enumerable[T::Module[top]]
64
61
  def gather_constants
65
62
  descendants_of(::ActiveRecord::Base).reject(&:abstract_class?)
66
63
  end
@@ -80,7 +80,6 @@ module Tapioca
80
80
  # ~~~
81
81
  #: [ConstantType = (singleton(ActiveRecord::Base) & Extensions::ActiveRecord)]
82
82
  class ActiveRecordStore < Compiler
83
- extend T::Sig
84
83
  include Helpers::ActiveRecordConstantsHelper
85
84
 
86
85
  # @override
@@ -132,10 +131,8 @@ module Tapioca
132
131
  end
133
132
 
134
133
  class << self
135
- extend T::Sig
136
-
137
134
  # @override
138
- #: -> T::Enumerable[Module]
135
+ #: -> Enumerable[T::Module[top]]
139
136
  def gather_constants
140
137
  descendants_of(::ActiveRecord::Base).reject(&:abstract_class?)
141
138
  end
@@ -83,8 +83,6 @@ module Tapioca
83
83
  # ~~~
84
84
  #: [ConstantType = singleton(::ActiveRecord::Base)]
85
85
  class ActiveRecordTypedStore < Compiler
86
- extend T::Sig
87
-
88
86
  # @override
89
87
  #: -> void
90
88
  def decorate
@@ -108,10 +106,8 @@ module Tapioca
108
106
  end
109
107
 
110
108
  class << self
111
- extend T::Sig
112
-
113
109
  # @override
114
- #: -> T::Enumerable[Module]
110
+ #: -> Enumerable[T::Module[top]]
115
111
  def gather_constants
116
112
  descendants_of(::ActiveRecord::Base).select do |klass|
117
113
  klass.include?(ActiveRecord::TypedStore::Behavior)
@@ -56,8 +56,6 @@ module Tapioca
56
56
  # ~~~
57
57
  #: [ConstantType = singleton(::ActiveResource::Base)]
58
58
  class ActiveResource < Compiler
59
- extend T::Sig
60
-
61
59
  # @override
62
60
  #: -> void
63
61
  def decorate
@@ -71,10 +69,8 @@ module Tapioca
71
69
  end
72
70
 
73
71
  class << self
74
- extend T::Sig
75
-
76
72
  # @override
77
- #: -> T::Enumerable[Module]
73
+ #: -> Enumerable[T::Module[top]]
78
74
  def gather_constants
79
75
  descendants_of(::ActiveResource::Base)
80
76
  end
@@ -38,10 +38,8 @@ module Tapioca
38
38
  # def photo=(attachable); end
39
39
  # end
40
40
  # ~~~
41
- #: [ConstantType = (Module & ::ActiveStorage::Reflection::ActiveRecordExtensions::ClassMethods)]
41
+ #: [ConstantType = (T::Module[top] & ::ActiveStorage::Reflection::ActiveRecordExtensions::ClassMethods)]
42
42
  class ActiveStorage < Compiler
43
- extend T::Sig
44
-
45
43
  # @override
46
44
  #: -> void
47
45
  def decorate
@@ -65,10 +63,8 @@ module Tapioca
65
63
  end
66
64
 
67
65
  class << self
68
- extend T::Sig
69
-
70
66
  # @override
71
- #: -> T::Enumerable[Module]
67
+ #: -> Enumerable[T::Module[top]]
72
68
  def gather_constants
73
69
  descendants_of(::ActiveRecord::Base)
74
70
  .reject(&:abstract_class?)
@@ -37,10 +37,8 @@ module Tapioca
37
37
  # mixes_in_class_methods(::Foo::ClassMethods)
38
38
  # end
39
39
  # ~~~
40
- #: [ConstantType = Module]
40
+ #: [ConstantType = T::Module[top]]
41
41
  class ActiveSupportConcern < Compiler
42
- extend T::Sig
43
-
44
42
  # @override
45
43
  #: -> void
46
44
  def decorate
@@ -62,10 +60,8 @@ module Tapioca
62
60
  end
63
61
 
64
62
  class << self
65
- extend T::Sig
66
-
67
63
  # @override
68
- #: -> T::Enumerable[Module]
64
+ #: -> Enumerable[T::Module[top]]
69
65
  def gather_constants
70
66
  all_modules.select do |mod|
71
67
  name_of(mod) && # i.e. not anonymous
@@ -76,10 +72,10 @@ module Tapioca
76
72
  end
77
73
 
78
74
  # Returns true when `mod` includes other concerns
79
- #: (Module mod) -> bool
75
+ #: (T::Module[top] mod) -> bool
80
76
  def has_dependencies?(mod) = dependencies_of(mod).any?
81
77
 
82
- #: (Module concern) -> Array[Module]
78
+ #: (T::Module[top] concern) -> Array[T::Module[top]]
83
79
  def dependencies_of(concern)
84
80
  concern.instance_variable_get(:@_dependencies) || []
85
81
  end
@@ -87,12 +83,12 @@ module Tapioca
87
83
 
88
84
  private
89
85
 
90
- #: (Module concern) -> Array[Module]
86
+ #: (T::Module[top] concern) -> Array[T::Module[top]]
91
87
  def dependencies_of(concern)
92
88
  self.class.dependencies_of(concern)
93
89
  end
94
90
 
95
- #: (?Module concern) -> Array[Module]
91
+ #: (?T::Module[top] concern) -> Array[T::Module[top]]
96
92
  def linearized_dependencies(concern = constant)
97
93
  # Grab all the dependencies of the concern
98
94
  dependencies = dependencies_of(concern)
@@ -61,8 +61,6 @@ module Tapioca
61
61
  # ~~~
62
62
  #: [ConstantType = singleton(::ActiveSupport::CurrentAttributes)]
63
63
  class ActiveSupportCurrentAttributes < Compiler
64
- extend T::Sig
65
-
66
64
  # @override
67
65
  #: -> void
68
66
  def decorate
@@ -74,11 +72,11 @@ module Tapioca
74
72
  current_attributes_methods_name = "GeneratedAttributeMethods"
75
73
  current_attributes.create_module(current_attributes_methods_name) do |generated_attribute_methods|
76
74
  dynamic_methods.each do |method|
77
- method = method.to_s
75
+ method = constant.instance_method(method)
78
76
  # We want to generate each method both on the class
79
- generate_method(current_attributes, method, class_method: true)
77
+ create_method_from_def(current_attributes, method, class_method: true)
80
78
  # and on the instance
81
- generate_method(generated_attribute_methods, method, class_method: false)
79
+ create_method_from_def(generated_attribute_methods, method, class_method: false)
82
80
  end
83
81
 
84
82
  instance_methods.each do |method|
@@ -94,10 +92,8 @@ module Tapioca
94
92
  end
95
93
 
96
94
  class << self
97
- extend T::Sig
98
-
99
95
  # @override
100
- #: -> T::Enumerable[Module]
96
+ #: -> Enumerable[T::Module[top]]
101
97
  def gather_constants
102
98
  descendants_of(::ActiveSupport::CurrentAttributes)
103
99
  end
@@ -114,17 +110,6 @@ module Tapioca
114
110
  def instance_methods_of_constant
115
111
  constant.instance_methods(false)
116
112
  end
117
-
118
- #: (RBI::Scope klass, String method, class_method: bool) -> void
119
- def generate_method(klass, method, class_method:)
120
- method_def = if class_method
121
- constant.method(method)
122
- else
123
- constant.instance_method(method)
124
- end
125
-
126
- create_method_from_def(klass, method_def, class_method: class_method)
127
- end
128
113
  end
129
114
  end
130
115
  end
@@ -0,0 +1,60 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ return unless defined?(ActiveSupport::EnvironmentInquirer)
5
+
6
+ module Tapioca
7
+ module Dsl
8
+ module Compilers
9
+ # `Tapioca::Dsl::Compilers::ActiveSupportEnvironmentInquirer` decorates an RBI file for non-default environment
10
+ # files in the `config/environments` directory.
11
+ #
12
+ # For example, in a Rails application with the following files:
13
+ #
14
+ # - config/environments/development.rb
15
+ # - config/environments/demo.rb
16
+ # - config/environments/production.rb
17
+ # - config/environments/staging.rb
18
+ # - config/environments/test.rb
19
+ #
20
+ # this compiler will produce an RBI file with the following content:
21
+ # ~~~rbi
22
+ # # typed: true
23
+ #
24
+ # class ActiveSupport::EnvironmentInquirer
25
+ # sig { returns(T::Boolean) }
26
+ # def demo?; end
27
+ #
28
+ # sig { returns(T::Boolean) }
29
+ # def staging?; end
30
+ # end
31
+ # ~~~
32
+ #: [ConstantType = singleton(::ActiveSupport::EnvironmentInquirer)]
33
+ class ActiveSupportEnvironmentInquirer < Compiler
34
+ # @override
35
+ #: -> void
36
+ def decorate
37
+ envs = Rails.root.glob("config/environments/*.rb").map { |f| f.basename(".rb").to_s }.sort
38
+ envs -= ::ActiveSupport::EnvironmentInquirer::DEFAULT_ENVIRONMENTS
39
+ return if envs.none?
40
+
41
+ root.create_path(::ActiveSupport::EnvironmentInquirer) do |mod|
42
+ envs.each do |env|
43
+ mod.create_method("#{env}?", return_type: "T::Boolean")
44
+ end
45
+ end
46
+ end
47
+
48
+ class << self
49
+ # @override
50
+ #: -> T::Enumerable[T::Module[top]]
51
+ def gather_constants
52
+ return [] unless defined?(Rails.application) && Rails.application
53
+
54
+ [::ActiveSupport::EnvironmentInquirer]
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -36,8 +36,6 @@ module Tapioca
36
36
  # ```
37
37
  #: [ConstantType = singleton(::Time)]
38
38
  class ActiveSupportTimeExt < Compiler
39
- extend T::Sig
40
-
41
39
  # @override
42
40
  #: -> void
43
41
  def decorate
@@ -55,10 +53,8 @@ module Tapioca
55
53
  end
56
54
 
57
55
  class << self
58
- extend T::Sig
59
-
60
56
  # @override
61
- #: -> T::Enumerable[Module]
57
+ #: -> Enumerable[T::Module[top]]
62
58
  def gather_constants
63
59
  [::Time]
64
60
  end
@@ -40,10 +40,8 @@ module Tapioca
40
40
  # def github=(value); end
41
41
  # end
42
42
  # ```
43
- #: [ConstantType = Module]
43
+ #: [ConstantType = T::Module[top]]
44
44
  class Config < Compiler
45
- extend T::Sig
46
-
47
45
  CONFIG_OPTIONS_SUFFIX = "ConfigOptions"
48
46
 
49
47
  # @override
@@ -93,10 +91,8 @@ module Tapioca
93
91
  end
94
92
 
95
93
  class << self
96
- extend T::Sig
97
-
98
94
  # @override
99
- #: -> T::Enumerable[Module]
95
+ #: -> Enumerable[T::Module[top]]
100
96
  def gather_constants
101
97
  name = ::Config.const_name
102
98
  return [] unless Object.const_defined?(name)
@@ -60,8 +60,6 @@ module Tapioca
60
60
  # ~~~
61
61
  #: [ConstantType = (singleton(::FrozenRecord::Base) & Extensions::FrozenRecord)]
62
62
  class FrozenRecord < Compiler
63
- extend T::Sig
64
-
65
63
  # @override
66
64
  #: -> void
67
65
  def decorate
@@ -85,10 +83,8 @@ module Tapioca
85
83
  end
86
84
 
87
85
  class << self
88
- extend T::Sig
89
-
90
86
  # @override
91
- #: -> T::Enumerable[Module]
87
+ #: -> Enumerable[T::Module[top]]
92
88
  def gather_constants
93
89
  descendants_of(::FrozenRecord::Base).reject(&:abstract_class?)
94
90
  end
@@ -36,8 +36,6 @@ module Tapioca
36
36
  # ~~~
37
37
  #: [ConstantType = singleton(GraphQL::Schema::InputObject)]
38
38
  class GraphqlInputObject < Compiler
39
- extend T::Sig
40
-
41
39
  # @override
42
40
  #: -> void
43
41
  def decorate
@@ -74,10 +72,8 @@ module Tapioca
74
72
  end
75
73
 
76
74
  class << self
77
- extend T::Sig
78
-
79
75
  # @override
80
- #: -> T::Enumerable[Module]
76
+ #: -> Enumerable[T::Module[top]]
81
77
  def gather_constants
82
78
  all_classes.select { |c| GraphQL::Schema::InputObject > c }
83
79
  end
@@ -37,8 +37,6 @@ module Tapioca
37
37
  # ~~~
38
38
  #: [ConstantType = singleton(GraphQL::Schema::Mutation)]
39
39
  class GraphqlMutation < Compiler
40
- extend T::Sig
41
-
42
40
  # @override
43
41
  #: -> void
44
42
  def decorate
@@ -71,10 +69,8 @@ module Tapioca
71
69
  end
72
70
 
73
71
  class << self
74
- extend T::Sig
75
-
76
72
  # @override
77
- #: -> T::Enumerable[Module]
73
+ #: -> Enumerable[T::Module[top]]
78
74
  def gather_constants
79
75
  all_classes.select { |c| GraphQL::Schema::Mutation > c && GraphQL::Schema::RelayClassicMutation != c }
80
76
  end
@@ -57,9 +57,7 @@ module Tapioca
57
57
  # ~~~
58
58
  #: [ConstantType = singleton(::ActiveRecord::Base)]
59
59
  class IdentityCache < Compiler
60
- extend T::Sig
61
-
62
- COLLECTION_TYPE = ->(type) { "T::Array[::#{type}]" } #: ^((Module | String) type) -> String
60
+ COLLECTION_TYPE = ->(type) { "T::Array[::#{type}]" } #: ^((T::Module[top] | String) type) -> String
63
61
 
64
62
  # @override
65
63
  #: -> void
@@ -92,10 +90,8 @@ module Tapioca
92
90
  end
93
91
 
94
92
  class << self
95
- extend T::Sig
96
-
97
93
  # @override
98
- #: -> T::Enumerable[Module]
94
+ #: -> Enumerable[T::Module[top]]
99
95
  def gather_constants
100
96
  descendants_of(::ActiveRecord::Base).select do |klass|
101
97
  ::IdentityCache::WithoutPrimaryIndex > klass
@@ -81,8 +81,6 @@ module Tapioca
81
81
  # ~~~
82
82
  #: [ConstantType = singleton(::JsonApiClient::Resource)]
83
83
  class JsonApiClientResource < Compiler
84
- extend T::Sig
85
-
86
84
  # @override
87
85
  #: -> void
88
86
  def decorate
@@ -106,10 +104,8 @@ module Tapioca
106
104
  end
107
105
 
108
106
  class << self
109
- extend T::Sig
110
-
111
107
  # @override
112
- #: -> T::Enumerable[Module]
108
+ #: -> Enumerable[T::Module[top]]
113
109
  def gather_constants
114
110
  all_modules.select do |c|
115
111
  name_of(c) && ::JsonApiClient::Resource > c
@@ -142,17 +138,7 @@ module Tapioca
142
138
  type = ::JsonApiClient::Schema::TypeFactory.type_for(property.type)
143
139
  return "T.untyped" if type.nil?
144
140
 
145
- sorbet_type = if type.respond_to?(:sorbet_type)
146
- line, file = type.method(:sorbet_type).source_location
147
-
148
- $stderr.puts <<~MESSAGE
149
- WARNING: `#sorbet_type` is deprecated. Please rename your method to `#__tapioca_type`."
150
-
151
- Defined on line #{line} of #{file}
152
- MESSAGE
153
-
154
- type.sorbet_type
155
- elsif type.respond_to?(:__tapioca_type)
141
+ tapioca_type = if type.respond_to?(:__tapioca_type)
156
142
  type.__tapioca_type
157
143
  elsif type == ::JsonApiClient::Schema::Types::Integer
158
144
  "::Integer"
@@ -171,9 +157,9 @@ module Tapioca
171
157
  end
172
158
 
173
159
  if property.default.nil?
174
- as_nilable_type(sorbet_type)
160
+ as_nilable_type(tapioca_type)
175
161
  else
176
- sorbet_type
162
+ tapioca_type
177
163
  end
178
164
  end
179
165