tapioca 0.4.24 → 0.5.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 +4 -4
- data/Gemfile +14 -14
- data/README.md +2 -2
- data/Rakefile +5 -7
- data/exe/tapioca +2 -2
- data/lib/tapioca/cli.rb +256 -2
- data/lib/tapioca/compilers/dsl/aasm.rb +122 -0
- data/lib/tapioca/compilers/dsl/action_controller_helpers.rb +52 -12
- data/lib/tapioca/compilers/dsl/action_mailer.rb +6 -9
- data/lib/tapioca/compilers/dsl/active_job.rb +8 -12
- data/lib/tapioca/compilers/dsl/active_model_attributes.rb +131 -0
- data/lib/tapioca/compilers/dsl/active_record_associations.rb +33 -54
- data/lib/tapioca/compilers/dsl/active_record_columns.rb +10 -105
- data/lib/tapioca/compilers/dsl/active_record_enum.rb +8 -10
- data/lib/tapioca/compilers/dsl/active_record_scope.rb +7 -10
- data/lib/tapioca/compilers/dsl/active_record_typed_store.rb +5 -8
- data/lib/tapioca/compilers/dsl/active_resource.rb +9 -37
- data/lib/tapioca/compilers/dsl/active_storage.rb +98 -0
- data/lib/tapioca/compilers/dsl/active_support_concern.rb +108 -0
- data/lib/tapioca/compilers/dsl/active_support_current_attributes.rb +13 -8
- data/lib/tapioca/compilers/dsl/base.rb +96 -82
- data/lib/tapioca/compilers/dsl/config.rb +111 -0
- data/lib/tapioca/compilers/dsl/frozen_record.rb +5 -7
- data/lib/tapioca/compilers/dsl/identity_cache.rb +66 -29
- data/lib/tapioca/compilers/dsl/protobuf.rb +19 -69
- data/lib/tapioca/compilers/dsl/sidekiq_worker.rb +25 -12
- data/lib/tapioca/compilers/dsl/smart_properties.rb +19 -31
- data/lib/tapioca/compilers/dsl/state_machines.rb +56 -78
- data/lib/tapioca/compilers/dsl/url_helpers.rb +7 -10
- data/lib/tapioca/compilers/dsl_compiler.rb +22 -38
- data/lib/tapioca/compilers/requires_compiler.rb +2 -2
- data/lib/tapioca/compilers/sorbet.rb +26 -5
- data/lib/tapioca/compilers/symbol_table/symbol_generator.rb +139 -154
- data/lib/tapioca/compilers/symbol_table/symbol_loader.rb +4 -4
- data/lib/tapioca/compilers/symbol_table_compiler.rb +1 -1
- data/lib/tapioca/compilers/todos_compiler.rb +1 -1
- data/lib/tapioca/config.rb +2 -0
- data/lib/tapioca/config_builder.rb +4 -2
- data/lib/tapioca/constant_locator.rb +6 -8
- data/lib/tapioca/gemfile.rb +26 -19
- data/lib/tapioca/generator.rb +127 -43
- data/lib/tapioca/generic_type_registry.rb +25 -98
- data/lib/tapioca/helpers/active_record_column_type_helper.rb +98 -0
- data/lib/tapioca/internal.rb +1 -9
- data/lib/tapioca/loader.rb +14 -48
- data/lib/tapioca/rbi_ext/model.rb +122 -0
- data/lib/tapioca/reflection.rb +131 -0
- data/lib/tapioca/sorbet_ext/fixed_hash_patch.rb +1 -1
- data/lib/tapioca/sorbet_ext/generic_name_patch.rb +72 -4
- data/lib/tapioca/sorbet_ext/name_patch.rb +1 -1
- data/lib/tapioca/version.rb +1 -1
- data/lib/tapioca.rb +2 -0
- metadata +34 -22
- data/lib/tapioca/cli/main.rb +0 -146
- data/lib/tapioca/core_ext/class.rb +0 -28
- data/lib/tapioca/core_ext/string.rb +0 -18
- data/lib/tapioca/rbi/model.rb +0 -405
- data/lib/tapioca/rbi/printer.rb +0 -410
- data/lib/tapioca/rbi/rewriters/group_nodes.rb +0 -106
- data/lib/tapioca/rbi/rewriters/nest_non_public_methods.rb +0 -65
- data/lib/tapioca/rbi/rewriters/nest_singleton_methods.rb +0 -42
- data/lib/tapioca/rbi/rewriters/sort_nodes.rb +0 -86
- data/lib/tapioca/rbi/visitor.rb +0 -21
@@ -0,0 +1,131 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Tapioca
|
5
|
+
module Reflection
|
6
|
+
extend T::Sig
|
7
|
+
extend self
|
8
|
+
|
9
|
+
CLASS_METHOD = T.let(Kernel.instance_method(:class), UnboundMethod)
|
10
|
+
CONSTANTS_METHOD = T.let(Module.instance_method(:constants), UnboundMethod)
|
11
|
+
NAME_METHOD = T.let(Module.instance_method(:name), UnboundMethod)
|
12
|
+
SINGLETON_CLASS_METHOD = T.let(Object.instance_method(:singleton_class), UnboundMethod)
|
13
|
+
ANCESTORS_METHOD = T.let(Module.instance_method(:ancestors), UnboundMethod)
|
14
|
+
SUPERCLASS_METHOD = T.let(Class.instance_method(:superclass), UnboundMethod)
|
15
|
+
OBJECT_ID_METHOD = T.let(BasicObject.instance_method(:__id__), UnboundMethod)
|
16
|
+
EQUAL_METHOD = T.let(BasicObject.instance_method(:equal?), UnboundMethod)
|
17
|
+
PUBLIC_INSTANCE_METHODS_METHOD = T.let(Module.instance_method(:public_instance_methods), UnboundMethod)
|
18
|
+
PROTECTED_INSTANCE_METHODS_METHOD = T.let(Module.instance_method(:protected_instance_methods), UnboundMethod)
|
19
|
+
PRIVATE_INSTANCE_METHODS_METHOD = T.let(Module.instance_method(:private_instance_methods), UnboundMethod)
|
20
|
+
|
21
|
+
sig { params(object: BasicObject).returns(Class).checked(:never) }
|
22
|
+
def class_of(object)
|
23
|
+
CLASS_METHOD.bind(object).call
|
24
|
+
end
|
25
|
+
|
26
|
+
sig { params(constant: Module).returns(T::Array[Symbol]) }
|
27
|
+
def constants_of(constant)
|
28
|
+
CONSTANTS_METHOD.bind(constant).call(false)
|
29
|
+
end
|
30
|
+
|
31
|
+
sig { params(constant: Module).returns(T.nilable(String)) }
|
32
|
+
def name_of(constant)
|
33
|
+
NAME_METHOD.bind(constant).call
|
34
|
+
end
|
35
|
+
|
36
|
+
sig { params(constant: Module).returns(Class) }
|
37
|
+
def singleton_class_of(constant)
|
38
|
+
SINGLETON_CLASS_METHOD.bind(constant).call
|
39
|
+
end
|
40
|
+
|
41
|
+
sig { params(constant: Module).returns(T::Array[Module]) }
|
42
|
+
def ancestors_of(constant)
|
43
|
+
ANCESTORS_METHOD.bind(constant).call
|
44
|
+
end
|
45
|
+
|
46
|
+
sig { params(constant: Class).returns(T.nilable(Class)) }
|
47
|
+
def superclass_of(constant)
|
48
|
+
SUPERCLASS_METHOD.bind(constant).call
|
49
|
+
end
|
50
|
+
|
51
|
+
sig { params(object: BasicObject).returns(Integer).checked(:never) }
|
52
|
+
def object_id_of(object)
|
53
|
+
OBJECT_ID_METHOD.bind(object).call
|
54
|
+
end
|
55
|
+
|
56
|
+
sig { params(object: BasicObject, other: BasicObject).returns(T::Boolean).checked(:never) }
|
57
|
+
def are_equal?(object, other)
|
58
|
+
EQUAL_METHOD.bind(object).call(other)
|
59
|
+
end
|
60
|
+
|
61
|
+
sig { params(constant: Module).returns(T::Array[Symbol]) }
|
62
|
+
def public_instance_methods_of(constant)
|
63
|
+
PUBLIC_INSTANCE_METHODS_METHOD.bind(constant).call
|
64
|
+
end
|
65
|
+
|
66
|
+
sig { params(constant: Module).returns(T::Array[Symbol]) }
|
67
|
+
def protected_instance_methods_of(constant)
|
68
|
+
PROTECTED_INSTANCE_METHODS_METHOD.bind(constant).call
|
69
|
+
end
|
70
|
+
|
71
|
+
sig { params(constant: Module).returns(T::Array[Symbol]) }
|
72
|
+
def private_instance_methods_of(constant)
|
73
|
+
PRIVATE_INSTANCE_METHODS_METHOD.bind(constant).call
|
74
|
+
end
|
75
|
+
|
76
|
+
sig { params(constant: Module).returns(T::Array[Module]) }
|
77
|
+
def inherited_ancestors_of(constant)
|
78
|
+
if Class === constant
|
79
|
+
ancestors_of(superclass_of(constant) || Object)
|
80
|
+
else
|
81
|
+
Module.ancestors
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
sig { params(constant: Module).returns(T.nilable(String)) }
|
86
|
+
def qualified_name_of(constant)
|
87
|
+
name = name_of(constant)
|
88
|
+
return if name.nil?
|
89
|
+
|
90
|
+
if name.start_with?("::")
|
91
|
+
name
|
92
|
+
else
|
93
|
+
"::#{name}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
sig { params(method: T.any(UnboundMethod, Method)).returns(T.untyped) }
|
98
|
+
def signature_of(method)
|
99
|
+
T::Private::Methods.signature_for_method(method)
|
100
|
+
rescue LoadError, StandardError
|
101
|
+
nil
|
102
|
+
end
|
103
|
+
|
104
|
+
sig { params(type: T::Types::Base).returns(String) }
|
105
|
+
def name_of_type(type)
|
106
|
+
type.to_s.gsub(/\bAttachedClass\b/, "T.attached_class")
|
107
|
+
end
|
108
|
+
|
109
|
+
# Returns an array with all classes that are < than the supplied class.
|
110
|
+
#
|
111
|
+
# class C; end
|
112
|
+
# descendants_of(C) # => []
|
113
|
+
#
|
114
|
+
# class B < C; end
|
115
|
+
# descendants_of(C) # => [B]
|
116
|
+
#
|
117
|
+
# class A < B; end
|
118
|
+
# descendants_of(C) # => [B, A]
|
119
|
+
#
|
120
|
+
# class D < C; end
|
121
|
+
# descendants_of(C) # => [B, A, D]
|
122
|
+
sig { type_parameters(:U).params(klass: T.type_parameter(:U)).returns(T::Array[T.type_parameter(:U)]) }
|
123
|
+
def descendants_of(klass)
|
124
|
+
result = ObjectSpace.each_object(klass.singleton_class).reject do |k|
|
125
|
+
T.cast(k, Module).singleton_class? || T.unsafe(k) == klass
|
126
|
+
end
|
127
|
+
|
128
|
+
T.unsafe(result)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -23,16 +23,16 @@ module T
|
|
23
23
|
def type_member(variance = :invariant, fixed: nil, lower: T.untyped, upper: BasicObject)
|
24
24
|
# `T::Generic#type_member` just instantiates a `T::Type::TypeMember` instance and returns it.
|
25
25
|
# We use that when registering the type member and then later return it from this method.
|
26
|
-
type_member =
|
27
|
-
Tapioca::GenericTypeRegistry.
|
26
|
+
type_member = Tapioca::TypeMember.new(variance, fixed, lower, upper)
|
27
|
+
Tapioca::GenericTypeRegistry.register_type_variable(self, type_member)
|
28
28
|
type_member
|
29
29
|
end
|
30
30
|
|
31
31
|
def type_template(variance = :invariant, fixed: nil, lower: T.untyped, upper: BasicObject)
|
32
32
|
# `T::Generic#type_template` just instantiates a `T::Type::TypeTemplate` instance and returns it.
|
33
33
|
# We use that when registering the type template and then later return it from this method.
|
34
|
-
type_template =
|
35
|
-
Tapioca::GenericTypeRegistry.
|
34
|
+
type_template = Tapioca::TypeTemplate.new(variance, fixed, lower, upper)
|
35
|
+
Tapioca::GenericTypeRegistry.register_type_variable(self, type_template)
|
36
36
|
type_template
|
37
37
|
end
|
38
38
|
end
|
@@ -64,3 +64,71 @@ module T
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
67
|
+
|
68
|
+
module Tapioca
|
69
|
+
class TypeMember < T::Types::TypeMember
|
70
|
+
extend T::Sig
|
71
|
+
|
72
|
+
sig { returns(T.nilable(String)) }
|
73
|
+
attr_accessor :name
|
74
|
+
|
75
|
+
sig { returns(T.untyped) }
|
76
|
+
attr_reader :fixed, :lower, :upper
|
77
|
+
|
78
|
+
sig { params(variance: Symbol, fixed: T.untyped, lower: T.untyped, upper: T.untyped).void }
|
79
|
+
def initialize(variance, fixed, lower, upper)
|
80
|
+
super(variance)
|
81
|
+
@fixed = fixed
|
82
|
+
@lower = lower
|
83
|
+
@upper = upper
|
84
|
+
end
|
85
|
+
|
86
|
+
sig { returns(String) }
|
87
|
+
def serialize
|
88
|
+
parts = []
|
89
|
+
parts << ":#{@variance}" unless @variance == :invariant
|
90
|
+
parts << "fixed: #{@fixed}" if @fixed
|
91
|
+
parts << "lower: #{@lower}" unless @lower == T.untyped
|
92
|
+
parts << "upper: #{@upper}" unless @upper == BasicObject
|
93
|
+
|
94
|
+
parameters = parts.join(", ")
|
95
|
+
|
96
|
+
serialized = +"type_member"
|
97
|
+
serialized << "(#{parameters})" unless parameters.empty?
|
98
|
+
serialized
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
class TypeTemplate < T::Types::TypeTemplate
|
103
|
+
extend T::Sig
|
104
|
+
|
105
|
+
sig { returns(T.nilable(String)) }
|
106
|
+
attr_accessor :name
|
107
|
+
|
108
|
+
sig { returns(T.untyped) }
|
109
|
+
attr_reader :fixed, :lower, :upper
|
110
|
+
|
111
|
+
sig { params(variance: Symbol, fixed: T.untyped, lower: T.untyped, upper: T.untyped).void }
|
112
|
+
def initialize(variance, fixed, lower, upper)
|
113
|
+
super(variance)
|
114
|
+
@fixed = fixed
|
115
|
+
@lower = lower
|
116
|
+
@upper = upper
|
117
|
+
end
|
118
|
+
|
119
|
+
sig { returns(String) }
|
120
|
+
def serialize
|
121
|
+
parts = []
|
122
|
+
parts << ":#{@variance}" unless @variance == :invariant
|
123
|
+
parts << "fixed: #{@fixed}" if @fixed
|
124
|
+
parts << "lower: #{@lower}" unless @lower == T.untyped
|
125
|
+
parts << "upper: #{@upper}" unless @upper == BasicObject
|
126
|
+
|
127
|
+
parameters = parts.join(", ")
|
128
|
+
|
129
|
+
serialized = +"type_template"
|
130
|
+
serialized << "(#{parameters})" unless parameters.empty?
|
131
|
+
serialized
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
data/lib/tapioca/version.rb
CHANGED
data/lib/tapioca.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
|
+
version: 0.5.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: 2021-08
|
14
|
+
date: 2021-09-08 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -42,47 +42,47 @@ dependencies:
|
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: 0.12.2
|
44
44
|
- !ruby/object:Gem::Dependency
|
45
|
-
name:
|
45
|
+
name: rbi
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|
47
47
|
requirements:
|
48
48
|
- - ">="
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version: 0
|
50
|
+
version: '0'
|
51
51
|
type: :runtime
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
55
|
- - ">="
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version: 0
|
57
|
+
version: '0'
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
|
-
name: sorbet-
|
59
|
+
name: sorbet-static
|
60
60
|
requirement: !ruby/object:Gem::Requirement
|
61
61
|
requirements:
|
62
62
|
- - ">="
|
63
63
|
- !ruby/object:Gem::Version
|
64
|
-
version:
|
64
|
+
version: 0.4.4471
|
65
65
|
type: :runtime
|
66
66
|
prerelease: false
|
67
67
|
version_requirements: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
69
|
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
version:
|
71
|
+
version: 0.4.4471
|
72
72
|
- !ruby/object:Gem::Dependency
|
73
|
-
name:
|
73
|
+
name: sorbet-runtime
|
74
74
|
requirement: !ruby/object:Gem::Requirement
|
75
75
|
requirements:
|
76
76
|
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
78
|
+
version: '0'
|
79
79
|
type: :runtime
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: !ruby/object:Gem::Requirement
|
82
82
|
requirements:
|
83
83
|
- - ">="
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
85
|
+
version: '0'
|
86
86
|
- !ruby/object:Gem::Dependency
|
87
87
|
name: spoom
|
88
88
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,6 +111,20 @@ dependencies:
|
|
111
111
|
- - ">="
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: 0.19.2
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
name: unparser
|
116
|
+
requirement: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
type: :runtime
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
114
128
|
description:
|
115
129
|
email:
|
116
130
|
- ruby@shopify.com
|
@@ -125,18 +139,22 @@ files:
|
|
125
139
|
- exe/tapioca
|
126
140
|
- lib/tapioca.rb
|
127
141
|
- lib/tapioca/cli.rb
|
128
|
-
- lib/tapioca/
|
142
|
+
- lib/tapioca/compilers/dsl/aasm.rb
|
129
143
|
- lib/tapioca/compilers/dsl/action_controller_helpers.rb
|
130
144
|
- lib/tapioca/compilers/dsl/action_mailer.rb
|
131
145
|
- lib/tapioca/compilers/dsl/active_job.rb
|
146
|
+
- lib/tapioca/compilers/dsl/active_model_attributes.rb
|
132
147
|
- lib/tapioca/compilers/dsl/active_record_associations.rb
|
133
148
|
- lib/tapioca/compilers/dsl/active_record_columns.rb
|
134
149
|
- lib/tapioca/compilers/dsl/active_record_enum.rb
|
135
150
|
- lib/tapioca/compilers/dsl/active_record_scope.rb
|
136
151
|
- lib/tapioca/compilers/dsl/active_record_typed_store.rb
|
137
152
|
- lib/tapioca/compilers/dsl/active_resource.rb
|
153
|
+
- lib/tapioca/compilers/dsl/active_storage.rb
|
154
|
+
- lib/tapioca/compilers/dsl/active_support_concern.rb
|
138
155
|
- lib/tapioca/compilers/dsl/active_support_current_attributes.rb
|
139
156
|
- lib/tapioca/compilers/dsl/base.rb
|
157
|
+
- lib/tapioca/compilers/dsl/config.rb
|
140
158
|
- lib/tapioca/compilers/dsl/frozen_record.rb
|
141
159
|
- lib/tapioca/compilers/dsl/identity_cache.rb
|
142
160
|
- lib/tapioca/compilers/dsl/protobuf.rb
|
@@ -154,20 +172,14 @@ files:
|
|
154
172
|
- lib/tapioca/config.rb
|
155
173
|
- lib/tapioca/config_builder.rb
|
156
174
|
- lib/tapioca/constant_locator.rb
|
157
|
-
- lib/tapioca/core_ext/class.rb
|
158
|
-
- lib/tapioca/core_ext/string.rb
|
159
175
|
- lib/tapioca/gemfile.rb
|
160
176
|
- lib/tapioca/generator.rb
|
161
177
|
- lib/tapioca/generic_type_registry.rb
|
178
|
+
- lib/tapioca/helpers/active_record_column_type_helper.rb
|
162
179
|
- lib/tapioca/internal.rb
|
163
180
|
- lib/tapioca/loader.rb
|
164
|
-
- lib/tapioca/
|
165
|
-
- lib/tapioca/
|
166
|
-
- lib/tapioca/rbi/rewriters/group_nodes.rb
|
167
|
-
- lib/tapioca/rbi/rewriters/nest_non_public_methods.rb
|
168
|
-
- lib/tapioca/rbi/rewriters/nest_singleton_methods.rb
|
169
|
-
- lib/tapioca/rbi/rewriters/sort_nodes.rb
|
170
|
-
- lib/tapioca/rbi/visitor.rb
|
181
|
+
- lib/tapioca/rbi_ext/model.rb
|
182
|
+
- lib/tapioca/reflection.rb
|
171
183
|
- lib/tapioca/sorbet_ext/fixed_hash_patch.rb
|
172
184
|
- lib/tapioca/sorbet_ext/generic_name_patch.rb
|
173
185
|
- lib/tapioca/sorbet_ext/name_patch.rb
|
@@ -185,7 +197,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
185
197
|
requirements:
|
186
198
|
- - ">="
|
187
199
|
- !ruby/object:Gem::Version
|
188
|
-
version: '2.
|
200
|
+
version: '2.6'
|
189
201
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
202
|
requirements:
|
191
203
|
- - ">="
|
data/lib/tapioca/cli/main.rb
DELETED
@@ -1,146 +0,0 @@
|
|
1
|
-
# typed: true
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
module Tapioca
|
5
|
-
module Cli
|
6
|
-
class Main < Thor
|
7
|
-
include(Thor::Actions)
|
8
|
-
|
9
|
-
class_option :prerequire,
|
10
|
-
aliases: ["--pre", "-b"],
|
11
|
-
banner: "file",
|
12
|
-
desc: "A file to be required before Bundler.require is called"
|
13
|
-
class_option :postrequire,
|
14
|
-
aliases: ["--post", "-a"],
|
15
|
-
banner: "file",
|
16
|
-
desc: "A file to be required after Bundler.require is called"
|
17
|
-
class_option :outdir,
|
18
|
-
aliases: ["--out", "-o"],
|
19
|
-
banner: "directory",
|
20
|
-
desc: "The output directory for generated RBI files"
|
21
|
-
class_option :generate_command,
|
22
|
-
aliases: ["--cmd", "-c"],
|
23
|
-
banner: "command",
|
24
|
-
desc: "The command to run to regenerate RBI files"
|
25
|
-
class_option :exclude,
|
26
|
-
aliases: ["-x"],
|
27
|
-
type: :array,
|
28
|
-
banner: "gem [gem ...]",
|
29
|
-
desc: "Excludes the given gem(s) from RBI generation"
|
30
|
-
class_option :typed_overrides,
|
31
|
-
aliases: ["--typed", "-t"],
|
32
|
-
type: :hash,
|
33
|
-
banner: "gem:level [gem:level ...]",
|
34
|
-
desc: "Overrides for typed sigils for generated gem RBIs"
|
35
|
-
|
36
|
-
map T.unsafe(%w[--version -v] => :__print_version)
|
37
|
-
|
38
|
-
desc "init", "initializes folder structure"
|
39
|
-
def init
|
40
|
-
create_config
|
41
|
-
create_post_require
|
42
|
-
generate_binstub
|
43
|
-
end
|
44
|
-
|
45
|
-
desc "require", "generate the list of files to be required by tapioca"
|
46
|
-
def require
|
47
|
-
Tapioca.silence_warnings do
|
48
|
-
generator.build_requires
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
desc "todo", "generate the list of unresolved constants"
|
53
|
-
def todo
|
54
|
-
Tapioca.silence_warnings do
|
55
|
-
generator.build_todos
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
desc "dsl [constant...]", "generate RBIs for dynamic methods"
|
60
|
-
option :generators,
|
61
|
-
type: :array,
|
62
|
-
aliases: ["--gen", "-g"],
|
63
|
-
banner: "generator [generator ...]",
|
64
|
-
desc: "Only run supplied DSL generators"
|
65
|
-
option :verify,
|
66
|
-
type: :boolean,
|
67
|
-
default: false,
|
68
|
-
desc: "Verifies RBIs are up-to-date"
|
69
|
-
option :quiet,
|
70
|
-
aliases: ["-q"],
|
71
|
-
type: :boolean,
|
72
|
-
desc: "Supresses file creation output"
|
73
|
-
def dsl(*constants)
|
74
|
-
Tapioca.silence_warnings do
|
75
|
-
generator.build_dsl(constants, should_verify: options[:verify], quiet: options[:quiet])
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
desc "generate [gem...]", "generate RBIs from gems"
|
80
|
-
def generate(*gems)
|
81
|
-
Tapioca.silence_warnings do
|
82
|
-
generator.build_gem_rbis(gems)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
desc "sync", "sync RBIs to Gemfile"
|
87
|
-
def sync
|
88
|
-
Tapioca.silence_warnings do
|
89
|
-
generator.sync_rbis_with_gemfile
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
desc "--version, -v", "show version"
|
94
|
-
def __print_version
|
95
|
-
puts "Tapioca v#{Tapioca::VERSION}"
|
96
|
-
end
|
97
|
-
|
98
|
-
private
|
99
|
-
|
100
|
-
def create_config
|
101
|
-
create_file(Config::SORBET_CONFIG, skip: true) do
|
102
|
-
<<~CONTENT
|
103
|
-
--dir
|
104
|
-
.
|
105
|
-
CONTENT
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def create_post_require
|
110
|
-
create_file(Config::DEFAULT_POSTREQUIRE, skip: true) do
|
111
|
-
<<~CONTENT
|
112
|
-
# typed: false
|
113
|
-
# frozen_string_literal: true
|
114
|
-
|
115
|
-
# Add your extra requires here
|
116
|
-
CONTENT
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def generate_binstub
|
121
|
-
bin_stub_exists = File.exist?("bin/tapioca")
|
122
|
-
installer = Bundler::Installer.new(Bundler.root, Bundler.definition)
|
123
|
-
spec = Bundler.definition.specs.find { |s| s.name == "tapioca" }
|
124
|
-
installer.generate_bundler_executable_stubs(spec, { force: true })
|
125
|
-
if bin_stub_exists
|
126
|
-
shell.say_status(:force, "bin/tapioca", :yellow)
|
127
|
-
else
|
128
|
-
shell.say_status(:create, "bin/tapioca", :green)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
no_commands do
|
133
|
-
def self.exit_on_failure?
|
134
|
-
true
|
135
|
-
end
|
136
|
-
|
137
|
-
def generator
|
138
|
-
current_command = T.must(current_command_chain.first)
|
139
|
-
@generator ||= Generator.new(
|
140
|
-
ConfigBuilder.from_options(current_command, options)
|
141
|
-
)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|