tapioca 0.4.18 → 0.4.19
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 +4 -4
- data/lib/tapioca/cli/main.rb +6 -0
- data/lib/tapioca/generic_type_registry.rb +29 -6
- data/lib/tapioca/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f64e1f934bd0528e93322b0ba116383fc7c053d1a0c35a3378664ecc3e08e69
|
4
|
+
data.tar.gz: 609a1125626ba712e042e2fb3346df852508595bf22c0187e8ded67b3c66ecf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ffc0244e7bd3d86ead0c42eb2cf9e940c84d4d838143b96247e908ded022477829c92c1838f2b933294b590eae49c2cd667c57bad6219be9b983ba3c556ddff
|
7
|
+
data.tar.gz: 33f534d1521e209052a7edff35fe95979497c80e3fcf78b136c3bb13ea3471f8e1158db83cafff5f3aaf79f0cfa6a00129fb20fb2ce92a018883f94fe61e0264
|
data/lib/tapioca/cli/main.rb
CHANGED
@@ -114,9 +114,15 @@ module Tapioca
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def generate_binstub
|
117
|
+
bin_stub_exists = File.exist?("bin/tapioca")
|
117
118
|
installer = Bundler::Installer.new(Bundler.root, Bundler.definition)
|
118
119
|
spec = Bundler.definition.specs.find { |s| s.name == "tapioca" }
|
119
120
|
installer.generate_bundler_executable_stubs(spec, { force: true })
|
121
|
+
if bin_stub_exists
|
122
|
+
shell.say_status(:force, "bin/tapioca", :yellow)
|
123
|
+
else
|
124
|
+
shell.say_status(:create, "bin/tapioca", :green)
|
125
|
+
end
|
120
126
|
end
|
121
127
|
|
122
128
|
no_commands do
|
@@ -51,14 +51,12 @@ module Tapioca
|
|
51
51
|
type_list = types.map { |type| T::Utils.coerce(type).name }.join(", ")
|
52
52
|
name = "#{name_of(constant)}[#{type_list}]"
|
53
53
|
|
54
|
-
# Create a
|
54
|
+
# Create a generic type with an overridden `name`
|
55
55
|
# method that returns the name we constructed above.
|
56
56
|
#
|
57
|
-
# Also, we try to memoize the
|
58
|
-
# we don't have to keep recreating
|
59
|
-
@generic_instances[name] ||= constant
|
60
|
-
clone.define_singleton_method(:name) { name }
|
61
|
-
end
|
57
|
+
# Also, we try to memoize the generic type based on the name, so that
|
58
|
+
# we don't have to keep recreating them all the time.
|
59
|
+
@generic_instances[name] ||= create_generic_type(constant, name)
|
62
60
|
end
|
63
61
|
|
64
62
|
sig do
|
@@ -94,6 +92,31 @@ module Tapioca
|
|
94
92
|
|
95
93
|
private
|
96
94
|
|
95
|
+
sig { params(constant: Module, name: String).returns(Module) }
|
96
|
+
def create_generic_type(constant, name)
|
97
|
+
generic_type = case constant
|
98
|
+
when Class
|
99
|
+
# For classes, we want to create a subclass, so that an instance of
|
100
|
+
# the generic class `Foo[Bar]` is still a `Foo`. That is:
|
101
|
+
# `Foo[Bar].new.is_a?(Foo)` should be true, which isn't the case
|
102
|
+
# if we just clone the class. But subclassing works just fine.
|
103
|
+
Class.new(constant)
|
104
|
+
else
|
105
|
+
# This can only be a module and it is fine to just clone modules
|
106
|
+
# since they can't have instances and will not have `is_a?` relationships.
|
107
|
+
# Moreover, we never `include`/`extend` any generic modules into the
|
108
|
+
# ancestor tree, so this doesn't become a problem with checking the
|
109
|
+
# instance of a class being `is_a?` of a module type.
|
110
|
+
constant.clone
|
111
|
+
end
|
112
|
+
|
113
|
+
# Let's set the `name` method to return the proper generic name
|
114
|
+
generic_type.define_singleton_method(:name) { name }
|
115
|
+
|
116
|
+
# Return the generic type we created
|
117
|
+
generic_type
|
118
|
+
end
|
119
|
+
|
97
120
|
# This method is called from intercepted calls to `type_member` and `type_template`.
|
98
121
|
# We get passed all the arguments to those methods, as well as the `T::Types::TypeVariable`
|
99
122
|
# instance generated by the Sorbet defined `type_member`/`type_template` call on `T::Generic`.
|
data/lib/tapioca/version.rb
CHANGED
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.4.
|
4
|
+
version: 0.4.19
|
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: 2021-03-
|
14
|
+
date: 2021-03-24 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|