tapioca 0.11.13 → 0.11.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 071fd87cab365673ec36e85a0cf657865d2c71d1650d02ae7c17ac3133f124f3
4
- data.tar.gz: 34a3b5e83928cb38eefbf57568ca8dc5d16c20ee6653da2ee591d6e3265d8d2a
3
+ metadata.gz: 52388d4c8afe40a2b6807e54bf1dd09701cb016ca1fed7ce5d3a691c3f93e0e5
4
+ data.tar.gz: 18550aa93626f63257b387154585dc2ae9e74c5aa17c7d4e2b82702bf5ce5b2b
5
5
  SHA512:
6
- metadata.gz: d97568a53647ceb3fe4e7bfd33dc3503cb95d8c95791dc0c0bf8429f9974c4a39d5d5e5aca16251ae866a07761f00ddbd5a224925b11c4a8378f682fd4deef1c
7
- data.tar.gz: f44cccf226efaa3b0ccda730daf3419acb3cdcaeec7c699c91ba9e2f8b4fe59a7e157331afff1723f69f09ff2fc3ff5a208222b2eb86c1738806170578a3ec2b
6
+ metadata.gz: c0be5c5d8108519bbda67d2498ff032273ad855a45c464a5a0acf0780412e7f4d3ee706322ef287fd2882ee0083f3c3fe1ab67611a16a6f45f5aa5a7aeb1a709
7
+ data.tar.gz: 6a87ab2319905c976cfb0b6a004c12d613a9200269268c6c452f8f7ba9175a1b7fd29c5d32de945a04614aff1de037463ad3c0fd090f883770a7f72d7f2f1476
@@ -36,7 +36,7 @@ module Tapioca
36
36
  sig { returns(T::Set[Module]) }
37
37
  def processable_constants
38
38
  @processable_constants ||= T.let(
39
- T::Set[Module].new(gather_constants).compare_by_identity,
39
+ T::Set[Module].new.compare_by_identity.merge(gather_constants),
40
40
  T.nilable(T::Set[Module]),
41
41
  )
42
42
  end
@@ -30,8 +30,13 @@ module Tapioca
30
30
  # # notify_user_job.rbi
31
31
  # # typed: true
32
32
  # class NotifyUserJob
33
- # sig { params(user: User).returns(T.any(NotifyUserJob, FalseClass)) }
34
- # def self.perform_later(user); end
33
+ # sig do
34
+ # params(
35
+ # user: User,
36
+ # block: T.nilable(T.proc.params(job: NotifyUserJob).void),
37
+ # ).returns(T.any(NotifyUserJob, FalseClass))
38
+ # end
39
+ # def self.perform_later(user, &block); end
35
40
  #
36
41
  # sig { params(user: User).returns(Mail) }
37
42
  # def self.perform_now(user); end
@@ -48,13 +53,14 @@ module Tapioca
48
53
 
49
54
  root.create_path(constant) do |job|
50
55
  method = constant.instance_method(:perform)
56
+ constant_name = name_of(constant)
51
57
  parameters = compile_method_parameters_to_rbi(method)
52
58
  return_type = compile_method_return_type_to_rbi(method)
53
59
 
54
60
  job.create_method(
55
61
  "perform_later",
56
- parameters: parameters,
57
- return_type: "T.any(#{name_of(constant)}, FalseClass)",
62
+ parameters: perform_later_parameters(parameters, constant_name),
63
+ return_type: "T.any(#{constant_name}, FalseClass)",
58
64
  class_method: true,
59
65
  )
60
66
 
@@ -67,6 +73,25 @@ module Tapioca
67
73
  end
68
74
  end
69
75
 
76
+ private
77
+
78
+ sig do
79
+ params(
80
+ parameters: T::Array[RBI::TypedParam],
81
+ constant_name: T.nilable(String),
82
+ ).returns(T::Array[RBI::TypedParam])
83
+ end
84
+ def perform_later_parameters(parameters, constant_name)
85
+ if ::Gem::Requirement.new(">= 7.0").satisfied_by?(::ActiveJob.gem_version)
86
+ parameters + [create_block_param(
87
+ "block",
88
+ type: "T.nilable(T.proc.params(job: #{constant_name}).void)",
89
+ )]
90
+ else
91
+ parameters
92
+ end
93
+ end
94
+
70
95
  class << self
71
96
  extend T::Sig
72
97
 
@@ -76,7 +76,12 @@ module Tapioca
76
76
  Class.new do
77
77
  T.unsafe(self).include(ActiveRecord::TestFixtures)
78
78
 
79
- T.unsafe(self).fixture_path = Rails.root.join("test", "fixtures")
79
+ if respond_to?(:fixture_paths=)
80
+ T.unsafe(self).fixture_paths = [Rails.root.join("test", "fixtures")]
81
+ else
82
+ T.unsafe(self).fixture_path = Rails.root.join("test", "fixtures")
83
+ end
84
+
80
85
  # https://github.com/rails/rails/blob/7c70791470fc517deb7c640bead9f1b47efb5539/activerecord/lib/active_record/test_fixtures.rb#L46
81
86
  singleton_class.define_method(:file_fixture_path) do
82
87
  Rails.root.join("test", "fixtures", "files")
@@ -55,7 +55,7 @@ module Tapioca
55
55
  root.create_path(constant) do |input_object|
56
56
  arguments.each do |argument|
57
57
  name = argument.keyword.to_s
58
- input_object.create_method(name, return_type: Helpers::GraphqlTypeHelper.type_for(argument))
58
+ input_object.create_method(name, return_type: Helpers::GraphqlTypeHelper.type_for(argument, constant))
59
59
  end
60
60
  end
61
61
  end
@@ -59,7 +59,7 @@ module Tapioca
59
59
  params = compile_method_parameters_to_rbi(method_def).map do |param|
60
60
  name = param.param.name
61
61
  argument = arguments_by_name.fetch(name, nil)
62
- create_typed_param(param.param, argument_type(argument))
62
+ create_typed_param(param.param, argument_type(argument, constant))
63
63
  end
64
64
 
65
65
  root.create_path(constant) do |mutation|
@@ -67,11 +67,16 @@ module Tapioca
67
67
  end
68
68
  end
69
69
 
70
- sig { params(argument: T.nilable(GraphQL::Schema::Argument)).returns(String) }
71
- def argument_type(argument)
70
+ sig do
71
+ params(
72
+ argument: T.nilable(GraphQL::Schema::Argument),
73
+ constant: T.class_of(GraphQL::Schema::Mutation),
74
+ ).returns(String)
75
+ end
76
+ def argument_type(argument, constant)
72
77
  return "T.untyped" unless argument
73
78
 
74
- Helpers::GraphqlTypeHelper.type_for(argument)
79
+ Helpers::GraphqlTypeHelper.type_for(argument, constant)
75
80
  end
76
81
 
77
82
  class << self
@@ -9,8 +9,13 @@ module Tapioca
9
9
 
10
10
  extend T::Sig
11
11
 
12
- sig { params(argument: GraphQL::Schema::Argument).returns(String) }
13
- def type_for(argument)
12
+ sig do
13
+ params(
14
+ argument: GraphQL::Schema::Argument,
15
+ constant: T.any(T.class_of(GraphQL::Schema::Mutation), T.class_of(GraphQL::Schema::InputObject)),
16
+ ).returns(String)
17
+ end
18
+ def type_for(argument, constant)
14
19
  type = if argument.loads
15
20
  loads_type = ::GraphQL::Schema::Wrapper.new(argument.loads)
16
21
  loads_type = loads_type.to_list_type if argument.type.list?
@@ -60,6 +65,17 @@ module Tapioca
60
65
  "T.untyped"
61
66
  end
62
67
 
68
+ if argument.prepare.is_a?(Symbol) || argument.prepare.is_a?(String)
69
+ if constant.respond_to?(argument.prepare)
70
+ prepare_method = constant.method(argument.prepare)
71
+ prepare_signature = Runtime::Reflection.signature_of(prepare_method)
72
+
73
+ if valid_return_type?(prepare_signature&.return_type)
74
+ parsed_type = prepare_signature.return_type&.to_s
75
+ end
76
+ end
77
+ end
78
+
63
79
  if type.list?
64
80
  parsed_type = "T::Array[#{parsed_type}]"
65
81
  end
@@ -77,6 +93,7 @@ module Tapioca
77
93
  def type_for_constant(constant)
78
94
  if constant.instance_methods.include?(:prepare)
79
95
  prepare_method = constant.instance_method(:prepare)
96
+
80
97
  prepare_signature = Runtime::Reflection.signature_of(prepare_method)
81
98
 
82
99
  return prepare_signature.return_type&.to_s if valid_return_type?(prepare_signature&.return_type)
@@ -130,7 +130,10 @@ module Tapioca
130
130
 
131
131
  sig { params(requested_constants: T::Array[Module], requested_paths: T::Array[Pathname]).returns(T::Set[Module]) }
132
132
  def gather_constants(requested_constants, requested_paths)
133
- constants = active_compilers.map(&:processable_constants).reduce(Set.new, :union)
133
+ constants = Set.new.compare_by_identity
134
+ active_compilers.each do |compiler|
135
+ constants.merge(compiler.processable_constants)
136
+ end
134
137
  constants = filter_anonymous_and_reloaded_constants(constants)
135
138
 
136
139
  constants &= requested_constants unless requested_constants.empty? && requested_paths.empty?
@@ -158,11 +161,12 @@ module Tapioca
158
161
 
159
162
  # Look up all the constants back from their names. The resulting constant set will be the
160
163
  # set of constants that are actually in memory with those names.
161
- constants_by_name
164
+ filtered_constants = constants_by_name
162
165
  .keys
163
166
  .map { |name| T.cast(Runtime::Reflection.constantize(name), Module) }
164
167
  .select { |mod| Runtime::Reflection.constant_defined?(mod) }
165
- .to_set
168
+
169
+ Set.new.compare_by_identity.merge(filtered_constants)
166
170
  end
167
171
 
168
172
  sig { params(constant: Module).returns(T.nilable(RBI::File)) }
@@ -97,12 +97,11 @@ module Tapioca
97
97
  # method and the parameter is required and there is a single
98
98
  # parameter and the signature also defines a single parameter and
99
99
  # the name of the method ends with a = character.
100
- writer_method_with_sig = (
100
+ writer_method_with_sig =
101
101
  signature && type == :req &&
102
102
  parameters.size == 1 &&
103
103
  signature.arg_types.size == 1 &&
104
104
  method_name[-1] == "="
105
- )
106
105
 
107
106
  if writer_method_with_sig
108
107
  method_name.delete_suffix("=")
@@ -67,8 +67,9 @@ module Tapioca
67
67
  sig { params(signature: T.untyped).returns(T::Boolean) }
68
68
  def signature_final?(signature)
69
69
  modules_with_final = T::Private::Methods.instance_variable_get(:@modules_with_final)
70
- final_methods = modules_with_final[signature.owner.object_id]
71
-
70
+ # In https://github.com/sorbet/sorbet/pull/7531, Sorbet changed internal hashes to be compared by identity,
71
+ # starting on version 0.5.11155
72
+ final_methods = modules_with_final[signature.owner] || modules_with_final[signature.owner.object_id]
72
73
  return false unless final_methods
73
74
 
74
75
  final_methods.include?(signature.method_name)
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.11.13"
5
+ VERSION = "0.11.14"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tapioca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.13
4
+ version: 0.11.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ufuk Kayserilioglu
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2023-12-06 00:00:00.000000000 Z
14
+ date: 2023-12-18 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler