tapioca 0.8.0 → 0.8.3

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: 69afa82ceccd1bd2fa9da5483011763edf2d1913d508a955a3c0b9c91fa2d04a
4
- data.tar.gz: b59721eb57b52b5be09ddfa443eaae90f0b74b6985506da7240159a4c34a21dd
3
+ metadata.gz: bb8747fff200d370504c4ae3119ab567335b4dc6b02a163a50217084a66bbe0d
4
+ data.tar.gz: 551715f2806d1038d4ed4d7ac9f23e7ca31051a8db153cf854878ad1aa529510
5
5
  SHA512:
6
- metadata.gz: 536a4d8e3c9b910f14e3808de67020c0dace80354d86a938a415f503fbc49acec859b3d95a1b6d8fbf3ea0f3be925a5ecfd1c071520eb158abda0ffd61e5ad30
7
- data.tar.gz: 7a43d61449279be2b77fb48e893452eb9a3086c9819fe0d6f75177e1bb8cc1c60748dc0696dcf97641ada93621be760815f356cb979eca771810b07835e0fcef
6
+ metadata.gz: 1a854413aaaa4f50464fd5be89cfd5de4770f9468a70627e8af556d2c953a0b1e4f86901a1907bebf8f367c2d94429bd52fe38ae977797582e1bf2e35432f00b
7
+ data.tar.gz: 00671d2d35d2e40fd7f2761c7e7b4994bb88b051311520b042fc950c0f1ce8c62017a8e79605f4397819f2233cb5c4342fe03f8f65b39c3fd25ca71e56a31db1
@@ -138,6 +138,7 @@ module Tapioca
138
138
 
139
139
  class GemSpec
140
140
  extend(T::Sig)
141
+ include GemHelper
141
142
 
142
143
  IGNORED_GEMS = T.let(["sorbet", "sorbet-static", "sorbet-runtime", "sorbet-static-and-runtime"].freeze,
143
144
  T::Array[String])
@@ -160,7 +161,7 @@ module Tapioca
160
161
 
161
162
  sig { params(gemfile_dir: String).returns(T::Boolean) }
162
163
  def ignore?(gemfile_dir)
163
- gem_ignored? || gem_in_app_dir?(gemfile_dir)
164
+ gem_ignored? || gem_in_app_dir?(gemfile_dir, full_gem_path)
164
165
  end
165
166
 
166
167
  sig { returns(String) }
@@ -284,27 +285,10 @@ module Tapioca
284
285
  false
285
286
  end
286
287
 
287
- sig { params(path: T.any(String, Pathname)).returns(String) }
288
- def to_realpath(path)
289
- path_string = path.to_s
290
- path_string = File.realpath(path_string) if File.exist?(path_string)
291
- path_string
292
- end
293
-
294
288
  sig { returns(T::Boolean) }
295
289
  def gem_ignored?
296
290
  IGNORED_GEMS.include?(name)
297
291
  end
298
-
299
- sig { params(gemfile_dir: String).returns(T::Boolean) }
300
- def gem_in_app_dir?(gemfile_dir)
301
- !gem_in_bundle_path? && full_gem_path.start_with?(gemfile_dir)
302
- end
303
-
304
- sig { returns(T::Boolean) }
305
- def gem_in_bundle_path?
306
- full_gem_path.start_with?(Bundler.bundle_path.to_s, Bundler.app_cache.to_s)
307
- end
308
292
  end
309
293
  end
310
294
  end
@@ -0,0 +1,26 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Tapioca
5
+ module GemHelper
6
+ extend T::Sig
7
+
8
+ sig { params(gemfile_dir: String, full_gem_path: String).returns(T::Boolean) }
9
+ def gem_in_app_dir?(gemfile_dir, full_gem_path)
10
+ !gem_in_bundle_path?(to_realpath(full_gem_path)) &&
11
+ full_gem_path.start_with?(to_realpath(gemfile_dir))
12
+ end
13
+
14
+ sig { params(full_gem_path: String).returns(T::Boolean) }
15
+ def gem_in_bundle_path?(full_gem_path)
16
+ full_gem_path.start_with?(Bundler.bundle_path.to_s, Bundler.app_cache.to_s)
17
+ end
18
+
19
+ sig { params(path: T.any(String, Pathname)).returns(String) }
20
+ def to_realpath(path)
21
+ path_string = path.to_s
22
+ path_string = File.realpath(path_string) if File.exist?(path_string)
23
+ path_string
24
+ end
25
+ end
26
+ end
@@ -5,6 +5,7 @@ require "tapioca"
5
5
  require "tapioca/runtime/reflection"
6
6
  require "tapioca/runtime/trackers"
7
7
  require "tapioca/runtime/dynamic_mixin_compiler"
8
+ require "tapioca/helpers/gem_helper"
8
9
  require "tapioca/runtime/loader"
9
10
  require "tapioca/helpers/sorbet_helper"
10
11
  require "tapioca/helpers/type_variable_helper"
@@ -5,6 +5,7 @@ module Tapioca
5
5
  module Runtime
6
6
  class Loader
7
7
  extend(T::Sig)
8
+ include Tapioca::GemHelper
8
9
 
9
10
  sig do
10
11
  params(gemfile: Tapioca::Gemfile, initialize_file: T.nilable(String), require_file: T.nilable(String)).void
@@ -54,8 +55,12 @@ module Tapioca
54
55
 
55
56
  safe_require("active_support/core_ext/class/subclasses")
56
57
 
58
+ project_path = Bundler.default_gemfile.parent.expand_path
57
59
  # We can use `Class#descendants` here, since we know Rails is loaded
58
- Object.const_get("Rails::Engine").descendants.reject(&:abstract_railtie?)
60
+ Object.const_get("Rails::Engine")
61
+ .descendants
62
+ .reject(&:abstract_railtie?)
63
+ .reject { |engine| gem_in_app_dir?(project_path, engine.config.root.to_path) }
59
64
  end
60
65
 
61
66
  sig { params(path: String).void }
@@ -21,47 +21,33 @@ module T
21
21
  Tapioca::Runtime::GenericTypeRegistry.register_type(constant, types)
22
22
  end
23
23
 
24
- def type_member(variance = :invariant, fixed: nil, lower: nil, upper: nil, &blk)
24
+ def type_member(variance = :invariant, fixed: nil, lower: nil, upper: nil, &bounds_proc)
25
25
  # `T::Generic#type_member` just instantiates a `T::Type::TypeMember` instance and returns it.
26
26
  # We use that when registering the type member and then later return it from this method.
27
- hash = if blk
28
- blk.call
29
- else
30
- {
31
- fixed: fixed,
32
- lower: lower,
33
- upper: upper,
34
- }
35
- end
36
-
37
27
  Tapioca::TypeVariableModule.new(
38
28
  T.cast(self, Module),
39
29
  Tapioca::TypeVariableModule::Type::Member,
40
30
  variance,
41
- **hash,
31
+ fixed,
32
+ lower,
33
+ upper,
34
+ bounds_proc
42
35
  ).tap do |type_variable|
43
36
  Tapioca::Runtime::GenericTypeRegistry.register_type_variable(self, type_variable)
44
37
  end
45
38
  end
46
39
 
47
- def type_template(variance = :invariant, fixed: nil, lower: nil, upper: nil, &blk)
40
+ def type_template(variance = :invariant, fixed: nil, lower: nil, upper: nil, &bounds_proc)
48
41
  # `T::Generic#type_template` just instantiates a `T::Type::TypeTemplate` instance and returns it.
49
42
  # We use that when registering the type template and then later return it from this method.
50
- hash = if blk
51
- blk.call
52
- else
53
- {
54
- fixed: fixed,
55
- lower: lower,
56
- upper: upper,
57
- }
58
- end
59
-
60
43
  Tapioca::TypeVariableModule.new(
61
44
  T.cast(self, Module),
62
45
  Tapioca::TypeVariableModule::Type::Template,
63
46
  variance,
64
- **hash,
47
+ fixed,
48
+ lower,
49
+ upper,
50
+ bounds_proc
65
51
  ).tap do |type_variable|
66
52
  Tapioca::Runtime::GenericTypeRegistry.register_type_variable(self, type_variable)
67
53
  end
@@ -136,18 +122,31 @@ module Tapioca
136
122
  end
137
123
  end
138
124
 
125
+ # rubocop:disable Metrics/ParameterLists
139
126
  sig do
140
- params(context: Module, type: Type, variance: Symbol, fixed: T.untyped, lower: T.untyped, upper: T.untyped).void
127
+ params(
128
+ context: Module,
129
+ type: Type,
130
+ variance: Symbol,
131
+ fixed: T.untyped,
132
+ lower: T.untyped,
133
+ upper: T.untyped,
134
+ bounds_proc: T.nilable(T.proc.returns(T::Hash[Symbol, T.untyped]))
135
+ ).void
141
136
  end
142
- def initialize(context, type, variance, fixed: nil, lower: nil, upper: nil)
137
+ def initialize(context, type, variance, fixed, lower, upper, bounds_proc)
143
138
  @context = context
144
139
  @type = type
145
140
  @variance = variance
146
- @fixed = fixed
147
- @lower = lower
148
- @upper = upper
141
+ @bounds_proc = if bounds_proc
142
+ bounds_proc
143
+ else
144
+ build_bounds_proc(fixed, lower, upper)
145
+ end
146
+
149
147
  super()
150
148
  end
149
+ # rubocop:enable Metrics/ParameterLists
151
150
 
152
151
  sig { returns(T.nilable(String)) }
153
152
  def name
@@ -170,9 +169,10 @@ module Tapioca
170
169
 
171
170
  sig { returns(String) }
172
171
  def serialize
173
- fixed = @fixed.to_s if @fixed
174
- upper = @upper.to_s if @upper
175
- lower = @lower.to_s if @lower
172
+ bounds = @bounds_proc.call
173
+ fixed = bounds[:fixed].to_s if bounds.key?(:fixed)
174
+ lower = bounds[:lower].to_s if bounds.key?(:lower)
175
+ upper = bounds[:upper].to_s if bounds.key?(:upper)
176
176
 
177
177
  TypeVariableHelper.serialize_type_variable(
178
178
  @type.serialize,
@@ -190,6 +190,19 @@ module Tapioca
190
190
 
191
191
  private
192
192
 
193
+ sig do
194
+ params(fixed: T.untyped, lower: T.untyped, upper: T.untyped)
195
+ .returns(T.proc.returns(T::Hash[Symbol, T.untyped]))
196
+ end
197
+ def build_bounds_proc(fixed, lower, upper)
198
+ bounds = {}
199
+ bounds[:fixed] = fixed unless fixed.nil?
200
+ bounds[:lower] = lower unless lower.nil?
201
+ bounds[:upper] = upper unless upper.nil?
202
+
203
+ -> { bounds }
204
+ end
205
+
193
206
  sig do
194
207
  type_parameters(:Result)
195
208
  .params(block: T.proc.returns(T.type_parameter(:Result)))
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.8.0"
5
+ VERSION = "0.8.3"
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.8.0
4
+ version: 0.8.3
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-05-13 00:00:00.000000000 Z
14
+ date: 2022-06-28 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -214,6 +214,7 @@ files:
214
214
  - lib/tapioca/gemfile.rb
215
215
  - lib/tapioca/helpers/cli_helper.rb
216
216
  - lib/tapioca/helpers/config_helper.rb
217
+ - lib/tapioca/helpers/gem_helper.rb
217
218
  - lib/tapioca/helpers/rbi_helper.rb
218
219
  - lib/tapioca/helpers/shims_helper.rb
219
220
  - lib/tapioca/helpers/signatures_helper.rb
@@ -263,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
263
264
  - !ruby/object:Gem::Version
264
265
  version: '0'
265
266
  requirements: []
266
- rubygems_version: 3.2.20
267
+ rubygems_version: 3.3.3
267
268
  signing_key:
268
269
  specification_version: 4
269
270
  summary: A Ruby Interface file generator for gems, core types and the Ruby standard