tapioca 0.4.13 → 0.4.18
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/Gemfile +0 -1
- data/README.md +4 -2
- data/exe/tapioca +17 -2
- data/lib/tapioca.rb +1 -27
- data/lib/tapioca/cli.rb +1 -108
- data/lib/tapioca/cli/main.rb +136 -0
- data/lib/tapioca/compilers/dsl/active_record_associations.rb +38 -7
- data/lib/tapioca/compilers/dsl/active_record_columns.rb +4 -4
- data/lib/tapioca/compilers/dsl/active_record_scope.rb +1 -1
- data/lib/tapioca/compilers/dsl/base.rb +1 -1
- data/lib/tapioca/compilers/dsl/url_helpers.rb +3 -3
- data/lib/tapioca/compilers/sorbet.rb +4 -1
- data/lib/tapioca/compilers/symbol_table/symbol_generator.rb +152 -49
- data/lib/tapioca/config.rb +1 -1
- data/lib/tapioca/config_builder.rb +7 -12
- data/lib/tapioca/gemfile.rb +30 -22
- data/lib/tapioca/generator.rb +127 -24
- data/lib/tapioca/generic_type_registry.rb +170 -0
- data/lib/tapioca/internal.rb +21 -0
- data/lib/tapioca/loader.rb +13 -2
- data/lib/tapioca/sorbet_ext/generic_name_patch.rb +66 -0
- data/lib/tapioca/sorbet_ext/name_patch.rb +16 -0
- data/lib/tapioca/version.rb +1 -1
- metadata +21 -2
data/lib/tapioca/loader.rb
CHANGED
@@ -99,17 +99,28 @@ module Tapioca
|
|
99
99
|
|
100
100
|
sig { void }
|
101
101
|
def eager_load_rails_app
|
102
|
+
rails = Object.const_get("Rails")
|
103
|
+
application = rails.application
|
104
|
+
|
102
105
|
if Object.const_defined?("ActiveSupport")
|
103
106
|
Object.const_get("ActiveSupport").run_load_hooks(
|
104
107
|
:before_eager_load,
|
105
|
-
|
108
|
+
application
|
106
109
|
)
|
107
110
|
end
|
111
|
+
|
108
112
|
if Object.const_defined?("Zeitwerk::Loader")
|
109
113
|
zeitwerk_loader = Object.const_get("Zeitwerk::Loader")
|
110
114
|
zeitwerk_loader.eager_load_all
|
111
115
|
end
|
112
|
-
|
116
|
+
|
117
|
+
if rails.respond_to?(:autoloaders) && rails.autoloaders.zeitwerk_enabled?
|
118
|
+
rails.autoloaders.each(&:eager_load)
|
119
|
+
end
|
120
|
+
|
121
|
+
if application.config.respond_to?(:eager_load_namespaces)
|
122
|
+
application.config.eager_load_namespaces.each(&:eager_load!)
|
123
|
+
end
|
113
124
|
end
|
114
125
|
|
115
126
|
sig { void }
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "tapioca/sorbet_ext/name_patch"
|
5
|
+
|
6
|
+
module T
|
7
|
+
module Generic
|
8
|
+
# This module intercepts calls to generic type instantiations and type variable definitions.
|
9
|
+
# Tapioca stores the data from those calls in a `GenericTypeRegistry` which can then be used
|
10
|
+
# to look up the original call details when we are trying to do code generation.
|
11
|
+
#
|
12
|
+
# We are interested in the data of the `[]`, `type_member` and `type_template` calls which
|
13
|
+
# are all needed to generate good generic information at runtime.
|
14
|
+
module TypeStoragePatch
|
15
|
+
def [](*types)
|
16
|
+
# `T::Generic#[]` just returns `self`, so let's call and store it.
|
17
|
+
constant = super
|
18
|
+
# `register_type` method builds and returns an instantiated clone of the generic type
|
19
|
+
# so, we just return that from this method as well.
|
20
|
+
Tapioca::GenericTypeRegistry.register_type(constant, types)
|
21
|
+
end
|
22
|
+
|
23
|
+
def type_member(variance = :invariant, fixed: nil, lower: T.untyped, upper: BasicObject)
|
24
|
+
# `T::Generic#type_member` just instantiates a `T::Type::TypeMember` instance and returns it.
|
25
|
+
# We use that when registering the type member and then later return it from this method.
|
26
|
+
type_member = super
|
27
|
+
Tapioca::GenericTypeRegistry.register_type_member(self, type_member, fixed, lower, upper)
|
28
|
+
type_member
|
29
|
+
end
|
30
|
+
|
31
|
+
def type_template(variance = :invariant, fixed: nil, lower: T.untyped, upper: BasicObject)
|
32
|
+
# `T::Generic#type_template` just instantiates a `T::Type::TypeTemplate` instance and returns it.
|
33
|
+
# We use that when registering the type template and then later return it from this method.
|
34
|
+
type_template = super
|
35
|
+
Tapioca::GenericTypeRegistry.register_type_template(self, type_template, fixed, lower, upper)
|
36
|
+
type_template
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
prepend TypeStoragePatch
|
41
|
+
end
|
42
|
+
|
43
|
+
module Types
|
44
|
+
class Simple
|
45
|
+
# This module intercepts calls to the `name` method for
|
46
|
+
# simple types, so that it can ask the name to the type if
|
47
|
+
# the type is generic, since, by this point, we've created
|
48
|
+
# a clone of that type with the `name` method returning the
|
49
|
+
# appropriate name for that specific concrete type.
|
50
|
+
module GenericNamePatch
|
51
|
+
def name
|
52
|
+
if T::Generic === @raw_type
|
53
|
+
# for types that are generic, use the name
|
54
|
+
# returned by the "name" method of this instance
|
55
|
+
@name ||= T.unsafe(@raw_type).name.freeze
|
56
|
+
else
|
57
|
+
# otherwise, fallback to the normal name lookup
|
58
|
+
super
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
prepend GenericNamePatch
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
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.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ufuk Kayserilioglu
|
@@ -11,8 +11,22 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2021-
|
14
|
+
date: 2021-03-22 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: bundler
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.17.3
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.17.3
|
16
30
|
- !ruby/object:Gem::Dependency
|
17
31
|
name: pry
|
18
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,6 +125,7 @@ files:
|
|
111
125
|
- exe/tapioca
|
112
126
|
- lib/tapioca.rb
|
113
127
|
- lib/tapioca/cli.rb
|
128
|
+
- lib/tapioca/cli/main.rb
|
114
129
|
- lib/tapioca/compilers/dsl/action_controller_helpers.rb
|
115
130
|
- lib/tapioca/compilers/dsl/action_mailer.rb
|
116
131
|
- lib/tapioca/compilers/dsl/active_record_associations.rb
|
@@ -141,7 +156,11 @@ files:
|
|
141
156
|
- lib/tapioca/core_ext/class.rb
|
142
157
|
- lib/tapioca/gemfile.rb
|
143
158
|
- lib/tapioca/generator.rb
|
159
|
+
- lib/tapioca/generic_type_registry.rb
|
160
|
+
- lib/tapioca/internal.rb
|
144
161
|
- lib/tapioca/loader.rb
|
162
|
+
- lib/tapioca/sorbet_ext/generic_name_patch.rb
|
163
|
+
- lib/tapioca/sorbet_ext/name_patch.rb
|
145
164
|
- lib/tapioca/version.rb
|
146
165
|
homepage: https://github.com/Shopify/tapioca
|
147
166
|
licenses:
|