tapioca 0.7.0 → 0.7.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef378ec3f3035d85d6aebfa4624896d216bcccd7d9332cbdc9d64be469b79b48
4
- data.tar.gz: 2f34d64fadd075ed1653ec26d27c73a02bfff949440fc6d1fd8bf80116161b48
3
+ metadata.gz: 4335f63c05a29d9ccaa0e0499af63ed4473f55532bd0a9aa012bbacf16a26666
4
+ data.tar.gz: 44edcd5f1de4552dd538a116ecc695d58f38837ad57c3f1979b65b6b649ccd82
5
5
  SHA512:
6
- metadata.gz: 78b6ce07ee08391457763a8e9069b0ff0efaa1be26cdeec7f334d2b45afa6ec12fd152d24c42d4c2b6834db25af77f74d6401bf577fd749ed446ef122dc01161
7
- data.tar.gz: 0b1998a9a72153d24747838606ff636cf8718efc67aa98e0c9d3ff01849d677840cd73f0adb8f289cc8c6f7e07b20bd37594bbcd1aea1b91761132fd07a1a9db
6
+ metadata.gz: 8f735efb4a5f069fa42fdfc7b7b4e0d62f7a962c816f35ebec0f02341d08984363656d384f91c42f1eecde2bcc574dbda4d4a05095bb367c81ac2b1e2fc7bb65
7
+ data.tar.gz: 6d76e4cc1e9ec2f725efa9332dc66883609ab8a49d70cd3edb31bda2d892928a0d9a879e18e6d2af94d6effee49ce0bb5ed79b9efa91dc4b4ede7d273de69ef6
@@ -74,10 +74,12 @@ module Tapioca
74
74
  .each_line
75
75
  .map do |line|
76
76
  next if line.include?("<")
77
- next if line.include?("class_of")
78
- line.strip.gsub("T.untyped::", "")
77
+
78
+ line.strip
79
+ .gsub(/T\.class_of\(([:\w]+)\)/, '\1') # Turn T.class_of(Foo)::Bar into Foo::Bar
79
80
  end
80
81
  .compact
82
+ .sort
81
83
  end
82
84
  end
83
85
  end
@@ -54,7 +54,7 @@ module Tapioca
54
54
  sig { returns(T::Set[Module]) }
55
55
  def self.processable_constants
56
56
  @processable_constants ||= T.let(
57
- Set.new(gather_constants).tap(&:compare_by_identity),
57
+ T::Set[Module].new(gather_constants).compare_by_identity,
58
58
  T.nilable(T::Set[Module])
59
59
  )
60
60
  T.must(@processable_constants)
@@ -60,6 +60,8 @@ module Tapioca
60
60
 
61
61
  sig { override.returns(T::Enumerable[Module]) }
62
62
  def self.gather_constants
63
+ return [] unless Rails.application
64
+
63
65
  [ActiveSupport::TestCase]
64
66
  end
65
67
 
@@ -109,6 +109,8 @@ module Tapioca
109
109
 
110
110
  sig { override.returns(T::Enumerable[Module]) }
111
111
  def self.gather_constants
112
+ return [] unless Rails.application
113
+
112
114
  Object.const_set(:GeneratedUrlHelpersModule, Rails.application.routes.named_routes.url_helpers_module)
113
115
  Object.const_set(:GeneratedPathHelpersModule, Rails.application.routes.named_routes.path_helpers_module)
114
116
 
@@ -160,7 +162,8 @@ module Tapioca
160
162
  superclass_ancestors = ancestors_of(superclass) if superclass
161
163
  end
162
164
 
163
- (ancestors_of(mod) - superclass_ancestors).any? { |ancestor| helper == ancestor }
165
+ ancestors = Set.new.compare_by_identity.merge(ancestors_of(mod)).subtract(superclass_ancestors)
166
+ ancestors.any? { |ancestor| helper == ancestor }
164
167
  end
165
168
  end
166
169
  end
@@ -1,11 +1,14 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "tapioca/helpers/signatures_helper"
5
+
4
6
  module Tapioca
5
7
  module Dsl
6
8
  module Helpers
7
9
  module ParamHelper
8
10
  extend T::Sig
11
+ include SignaturesHelper
9
12
 
10
13
  sig { params(name: String, type: String).returns(RBI::TypedParam) }
11
14
  def create_param(name, type:)
@@ -44,7 +47,7 @@ module Tapioca
44
47
 
45
48
  sig { params(param: RBI::Param, type: String).returns(RBI::TypedParam) }
46
49
  def create_typed_param(param, type)
47
- RBI::TypedParam.new(param: param, type: type)
50
+ RBI::TypedParam.new(param: param, type: sanitize_signature_types(type))
48
51
  end
49
52
  end
50
53
  end
@@ -53,7 +53,7 @@ module Tapioca
53
53
  end
54
54
  def run(&blk)
55
55
  constants_to_process = gather_constants(requested_constants)
56
- .select { |c| Runtime::Reflection.name_of(c) && Module === c } # Filter anonymous or value constants
56
+ .select { |c| Module === c } # Filter value constants out
57
57
  .sort_by! { |c| T.must(Runtime::Reflection.name_of(c)) }
58
58
 
59
59
  if constants_to_process.empty?
@@ -112,10 +112,37 @@ module Tapioca
112
112
  sig { params(requested_constants: T::Array[Module]).returns(T::Set[Module]) }
113
113
  def gather_constants(requested_constants)
114
114
  constants = compilers.map(&:processable_constants).reduce(Set.new, :union)
115
+ constants = filter_anonymous_and_reloaded_constants(constants)
116
+
115
117
  constants &= requested_constants unless requested_constants.empty?
116
118
  constants
117
119
  end
118
120
 
121
+ sig { params(constants: T::Set[Module]).returns(T::Set[Module]) }
122
+ def filter_anonymous_and_reloaded_constants(constants)
123
+ # Group constants by their names
124
+ constants_by_name = constants
125
+ .group_by { |c| T.must(Runtime::Reflection.name_of(c)) }
126
+ .select { |name, _| !name.nil? }
127
+
128
+ # Find the constants that have been reloaded
129
+ reloaded_constants = constants_by_name.select { |_, constants| constants.size > 1 }.keys
130
+
131
+ unless reloaded_constants.empty?
132
+ reloaded_constant_names = reloaded_constants.map { |name| "`#{name}`" }.join(", ")
133
+
134
+ $stderr.puts("WARNING: Multiple constants with the same name: #{reloaded_constant_names}")
135
+ $stderr.puts("Make sure some object is not holding onto these constants during an app reload.")
136
+ end
137
+
138
+ # Look up all the constants back from their names. The resulting constant set will be the
139
+ # set of constants that are actually in memory with those names.
140
+ constants_by_name
141
+ .keys
142
+ .map { |name| T.cast(Runtime::Reflection.constantize(name), Module) }
143
+ .to_set
144
+ end
145
+
119
146
  sig { params(constant: Module).returns(T.nilable(RBI::File)) }
120
147
  def rbi_for_constant(constant)
121
148
  file = RBI::File.new(strictness: "true")
@@ -8,7 +8,7 @@ module Tapioca
8
8
  extend T::Sig
9
9
 
10
10
  include Runtime::Reflection
11
- include RBIHelper
11
+ include SignaturesHelper
12
12
 
13
13
  TYPE_PARAMETER_MATCHER = /T\.type_parameter\(:?([[:word:]]+)\)/
14
14
 
@@ -8,7 +8,7 @@ module Tapioca
8
8
  class Pipeline
9
9
  extend T::Sig
10
10
  include Runtime::Reflection
11
- include RBIHelper
11
+ include SignaturesHelper
12
12
 
13
13
  IGNORED_SYMBOLS = T.let(["YAML", "MiniTest", "Mutex"], T::Array[String])
14
14
 
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- module RBIHelper
5
+ module SignaturesHelper
6
6
  extend T::Sig
7
7
 
8
8
  sig { params(sig_string: String).returns(String) }
@@ -11,7 +11,7 @@ require "tapioca/sorbet_ext/fixed_hash_patch"
11
11
  require "tapioca/runtime/generic_type_registry"
12
12
  require "tapioca/helpers/cli_helper"
13
13
  require "tapioca/helpers/config_helper"
14
- require "tapioca/helpers/rbi_helper"
14
+ require "tapioca/helpers/signatures_helper"
15
15
  require "tapioca/helpers/shims_helper"
16
16
  require "tapioca/helpers/sorbet_helper"
17
17
  require "tapioca/commands"
@@ -111,8 +111,10 @@ module Tapioca
111
111
  constant.clone
112
112
  end
113
113
 
114
- # Let's set the `name` method to return the proper generic name
115
- generic_type.define_singleton_method(:name) { name }
114
+ # Let's set the `name` and `to_s` methods to return the proper generic name
115
+ name_proc = -> { name }
116
+ generic_type.define_singleton_method(:name, name_proc)
117
+ generic_type.define_singleton_method(:to_s, name_proc)
116
118
 
117
119
  # We need to define a `<=` method on the cloned constant, so that Sorbet
118
120
  # can do covariance/contravariance checks on the type variables.
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.7.0"
5
+ VERSION = "0.7.1"
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.7.0
4
+ version: 0.7.1
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: 2022-02-17 00:00:00.000000000 Z
14
+ date: 2022-03-29 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -50,7 +50,7 @@ dependencies:
50
50
  version: 0.0.0
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: 0.0.12
53
+ version: 0.0.14
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -60,7 +60,7 @@ dependencies:
60
60
  version: 0.0.0
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: 0.0.12
63
+ version: 0.0.14
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: sorbet-runtime
66
66
  requirement: !ruby/object:Gem::Requirement
@@ -212,8 +212,8 @@ files:
212
212
  - lib/tapioca/gemfile.rb
213
213
  - lib/tapioca/helpers/cli_helper.rb
214
214
  - lib/tapioca/helpers/config_helper.rb
215
- - lib/tapioca/helpers/rbi_helper.rb
216
215
  - lib/tapioca/helpers/shims_helper.rb
216
+ - lib/tapioca/helpers/signatures_helper.rb
217
217
  - lib/tapioca/helpers/sorbet_helper.rb
218
218
  - lib/tapioca/helpers/test/content.rb
219
219
  - lib/tapioca/helpers/test/dsl_compiler.rb