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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3709ab7f54589bdf97715ffc2cc7c3a98ad703a6e318a264db70429078cdf26
4
- data.tar.gz: 3e38366a54f9b3286de28a2b6d557762b2cf564848b8184a76aadc75504a41fb
3
+ metadata.gz: 5f64e1f934bd0528e93322b0ba116383fc7c053d1a0c35a3378664ecc3e08e69
4
+ data.tar.gz: 609a1125626ba712e042e2fb3346df852508595bf22c0187e8ded67b3c66ecf2
5
5
  SHA512:
6
- metadata.gz: 4ef5e31a85a71607340ad54e2fff59b1a5bd0d3f81b1481bd4830ca5e73e5ea9ed1504d38808d8bf49a9686276685167a35103769fdb30d66b61362c4d9c072b
7
- data.tar.gz: e0b1daab32f024cc5f3f1fc019b5c1dcd040ce0657e59b81d736702e3cb380a9e7265397f108f4787163e50d9b31e793b960cd33f875cf45a061cee17fa1857e
6
+ metadata.gz: 0ffc0244e7bd3d86ead0c42eb2cf9e940c84d4d838143b96247e908ded022477829c92c1838f2b933294b590eae49c2cd667c57bad6219be9b983ba3c556ddff
7
+ data.tar.gz: 33f534d1521e209052a7edff35fe95979497c80e3fcf78b136c3bb13ea3471f8e1158db83cafff5f3aaf79f0cfa6a00129fb20fb2ce92a018883f94fe61e0264
@@ -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 clone of the constant with an overridden `name`
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 clone based on the name, so that
58
- # we don't have to keep recreating clones all the time.
59
- @generic_instances[name] ||= constant.clone.tap do |clone|
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`.
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.4.18"
5
+ VERSION = "0.4.19"
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.4.18
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-22 00:00:00.000000000 Z
14
+ date: 2021-03-24 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler