tapioca 0.16.1 → 0.16.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tapioca/dsl/compiler.rb +35 -2
- data/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb +34 -5
- data/lib/tapioca/dsl/pipeline.rb +1 -0
- data/lib/tapioca/gem/listeners/sorbet_enums.rb +6 -3
- data/lib/tapioca/helpers/source_uri.rb +8 -1
- data/lib/tapioca/rbi_formatter.rb +1 -1
- data/lib/tapioca/runtime/reflection.rb +1 -1
- data/lib/tapioca/version.rb +1 -1
- metadata +5 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61d9bbc2b60ce6dda54eea3d826374ca132938ddcdcc8185a731124bbad31704
|
4
|
+
data.tar.gz: 35aec9d2e19694a7737ff32b7a1d1863b24e255f327d87adbc42e435bcef048c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d09845c43897689c8b04ca565d22a9dc817fd8100276624ffc21a83538d3584e70909df6007aee6d360abbd63ff2842132db1346483d1faf9615500e4b3c988
|
7
|
+
data.tar.gz: b6ec214e91ed9b14fea2eefc00e396c4ea45157995dfdc52f98494da9498025bfa033b807324757f877768819e68ff04ff32dd0e10f93642dbb48e89dcd77451
|
data/lib/tapioca/dsl/compiler.rb
CHANGED
@@ -25,6 +25,8 @@ module Tapioca
|
|
25
25
|
sig { returns(T::Hash[String, T.untyped]) }
|
26
26
|
attr_reader :options
|
27
27
|
|
28
|
+
@@requested_constants = T.let([], T::Array[Module]) # rubocop:disable Style/ClassVars
|
29
|
+
|
28
30
|
class << self
|
29
31
|
extend T::Sig
|
30
32
|
|
@@ -44,12 +46,39 @@ module Tapioca
|
|
44
46
|
)
|
45
47
|
end
|
46
48
|
|
49
|
+
sig { params(constants: T::Array[Module]).void }
|
50
|
+
def requested_constants=(constants)
|
51
|
+
@@requested_constants = constants # rubocop:disable Style/ClassVars
|
52
|
+
end
|
53
|
+
|
47
54
|
private
|
48
55
|
|
56
|
+
sig do
|
57
|
+
type_parameters(:U)
|
58
|
+
.params(klass: T.all(T::Class[T.anything], T.type_parameter(:U)))
|
59
|
+
.returns(T::Array[T.type_parameter(:U)])
|
60
|
+
end
|
61
|
+
def descendants_of(klass)
|
62
|
+
if @@requested_constants.any?
|
63
|
+
T.cast(
|
64
|
+
@@requested_constants.select do |k|
|
65
|
+
k < klass && !k.singleton_class?
|
66
|
+
end,
|
67
|
+
T::Array[T.type_parameter(:U)],
|
68
|
+
)
|
69
|
+
else
|
70
|
+
super
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
49
74
|
sig { returns(T::Enumerable[T::Class[T.anything]]) }
|
50
75
|
def all_classes
|
51
76
|
@all_classes ||= T.let(
|
52
|
-
|
77
|
+
if @@requested_constants.any?
|
78
|
+
@@requested_constants.grep(Class)
|
79
|
+
else
|
80
|
+
ObjectSpace.each_object(Class)
|
81
|
+
end,
|
53
82
|
T.nilable(T::Enumerable[T::Class[T.anything]]),
|
54
83
|
)
|
55
84
|
end
|
@@ -57,7 +86,11 @@ module Tapioca
|
|
57
86
|
sig { returns(T::Enumerable[Module]) }
|
58
87
|
def all_modules
|
59
88
|
@all_modules ||= T.let(
|
60
|
-
|
89
|
+
if @@requested_constants.any?
|
90
|
+
@@requested_constants.select { |k| k.is_a?(Module) }
|
91
|
+
else
|
92
|
+
ObjectSpace.each_object(Module)
|
93
|
+
end,
|
61
94
|
T.nilable(T::Enumerable[Module]),
|
62
95
|
)
|
63
96
|
end
|
@@ -88,17 +88,24 @@ module Tapioca
|
|
88
88
|
sig { returns([String, String]) }
|
89
89
|
def id_type
|
90
90
|
if @constant.respond_to?(:composite_primary_key?) && T.unsafe(@constant).composite_primary_key?
|
91
|
-
@constant.primary_key
|
92
|
-
|
93
|
-
|
94
|
-
|
91
|
+
primary_key_columns = @constant.primary_key
|
92
|
+
|
93
|
+
getters = []
|
94
|
+
setters = []
|
95
|
+
|
96
|
+
primary_key_columns.each do |column|
|
97
|
+
getter, setter = column_type_for(column)
|
98
|
+
getters << getter
|
99
|
+
setters << setter
|
95
100
|
end
|
101
|
+
|
102
|
+
["[#{getters.join(", ")}]", "[#{setters.join(", ")}]"]
|
96
103
|
else
|
97
104
|
column_type_for(@constant.primary_key)
|
98
105
|
end
|
99
106
|
end
|
100
107
|
|
101
|
-
sig { params(column_name: String).returns([String, String]) }
|
108
|
+
sig { params(column_name: T.nilable(String)).returns([String, String]) }
|
102
109
|
def column_type_for(column_name)
|
103
110
|
return ["T.untyped", "T.untyped"] if @column_type_option.untyped?
|
104
111
|
|
@@ -155,6 +162,8 @@ module Tapioca
|
|
155
162
|
"::ActiveSupport::TimeWithZone"
|
156
163
|
when ActiveRecord::Enum::EnumType
|
157
164
|
"::String"
|
165
|
+
when ActiveRecord::Type::Binary
|
166
|
+
"::String"
|
158
167
|
when ActiveRecord::Type::Serialized
|
159
168
|
serialized_column_type(column_type)
|
160
169
|
when ->(type) {
|
@@ -177,11 +186,31 @@ module Tapioca
|
|
177
186
|
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Hstore === type
|
178
187
|
}
|
179
188
|
"T::Hash[::String, ::String]"
|
189
|
+
when ->(type) {
|
190
|
+
defined?(ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Interval) &&
|
191
|
+
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Interval === type
|
192
|
+
}
|
193
|
+
"::ActiveSupport::Duration"
|
180
194
|
when ->(type) {
|
181
195
|
defined?(ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array) &&
|
182
196
|
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array === type
|
183
197
|
}
|
184
198
|
"T::Array[#{type_for_activerecord_value(column_type.subtype, column_nullability:)}]"
|
199
|
+
when ->(type) {
|
200
|
+
defined?(ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Bit) &&
|
201
|
+
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Bit === type
|
202
|
+
}
|
203
|
+
"::String"
|
204
|
+
when ->(type) {
|
205
|
+
defined?(ActiveRecord::ConnectionAdapters::PostgreSQL::OID::BitVarying) &&
|
206
|
+
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::BitVarying === type
|
207
|
+
}
|
208
|
+
"::String"
|
209
|
+
when ->(type) {
|
210
|
+
defined?(ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Range) &&
|
211
|
+
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Range === type
|
212
|
+
}
|
213
|
+
"T::Range[#{type_for_activerecord_value(column_type.subtype, column_nullability:)}]"
|
185
214
|
else
|
186
215
|
as_non_nilable_if_persisted_and_not_nullable(
|
187
216
|
ActiveModelTypeHelper.type_for(column_type),
|
data/lib/tapioca/dsl/pipeline.rb
CHANGED
@@ -145,6 +145,7 @@ module Tapioca
|
|
145
145
|
).returns(T::Set[Module])
|
146
146
|
end
|
147
147
|
def gather_constants(requested_constants, requested_paths, skipped_constants)
|
148
|
+
Compiler.requested_constants = requested_constants
|
148
149
|
constants = Set.new.compare_by_identity
|
149
150
|
active_compilers.each do |compiler|
|
150
151
|
constants.merge(compiler.processable_constants)
|
@@ -14,11 +14,14 @@ module Tapioca
|
|
14
14
|
constant = event.constant
|
15
15
|
return unless T::Enum > event.constant # rubocop:disable Style/InvertibleUnlessCondition
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
enum_block = RBI::TEnumBlock.new
|
18
|
+
|
19
|
+
T.unsafe(constant).values.each do |enum_type|
|
20
|
+
enum_name = enum_type.instance_variable_get(:@const_name).to_s
|
21
|
+
enum_block << RBI::Const.new(enum_name, "new")
|
19
22
|
end
|
20
23
|
|
21
|
-
event.node <<
|
24
|
+
event.node << enum_block
|
22
25
|
end
|
23
26
|
|
24
27
|
sig { override.params(event: NodeAdded).returns(T::Boolean) }
|
@@ -18,6 +18,13 @@ module URI
|
|
18
18
|
T::Array[Symbol],
|
19
19
|
)
|
20
20
|
|
21
|
+
# `uri` for Ruby 3.4 switched the default parser from RFC2396 to RFC3986. The new parser emits a deprecation
|
22
|
+
# warning on a few methods and delegates them to RFC2396, namely `extract`/`make_regexp`/`escape`/`unescape`.
|
23
|
+
# On earlier versions of the uri gem, the RFC2396_PARSER constant doesn't exist, so it needs some special
|
24
|
+
# handling to select a parser that doesn't emit deprecations. While it was backported to Ruby 3.1, users may
|
25
|
+
# have the uri gem in their own bundle and thus not use a compatible version.
|
26
|
+
PARSER = T.let(const_defined?(:RFC2396_PARSER) ? RFC2396_PARSER : DEFAULT_PARSER, RFC2396_Parser)
|
27
|
+
|
21
28
|
alias_method(:gem_name, :host)
|
22
29
|
alias_method(:line_number, :fragment)
|
23
30
|
|
@@ -40,7 +47,7 @@ module URI
|
|
40
47
|
{
|
41
48
|
scheme: "source",
|
42
49
|
host: gem_name,
|
43
|
-
path:
|
50
|
+
path: PARSER.escape("/#{gem_version}/#{path}"),
|
44
51
|
fragment: line_number,
|
45
52
|
}
|
46
53
|
)
|
@@ -143,7 +143,7 @@ module Tapioca
|
|
143
143
|
|
144
144
|
sig { params(type: T::Types::Base).returns(String) }
|
145
145
|
def name_of_type(type)
|
146
|
-
type.to_s
|
146
|
+
type.to_s
|
147
147
|
end
|
148
148
|
|
149
149
|
sig { params(constant: Module, method: Symbol).returns(Method) }
|
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.16.
|
4
|
+
version: 0.16.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: 2024-
|
14
|
+
date: 2024-10-03 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -59,20 +59,14 @@ dependencies:
|
|
59
59
|
name: rbi
|
60
60
|
requirement: !ruby/object:Gem::Requirement
|
61
61
|
requirements:
|
62
|
-
- - "
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
version: 0.1.14
|
65
|
-
- - "<"
|
62
|
+
- - "~>"
|
66
63
|
- !ruby/object:Gem::Version
|
67
64
|
version: '0.2'
|
68
65
|
type: :runtime
|
69
66
|
prerelease: false
|
70
67
|
version_requirements: !ruby/object:Gem::Requirement
|
71
68
|
requirements:
|
72
|
-
- - "
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: 0.1.14
|
75
|
-
- - "<"
|
69
|
+
- - "~>"
|
76
70
|
- !ruby/object:Gem::Version
|
77
71
|
version: '0.2'
|
78
72
|
- !ruby/object:Gem::Dependency
|
@@ -290,7 +284,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
290
284
|
- !ruby/object:Gem::Version
|
291
285
|
version: '0'
|
292
286
|
requirements: []
|
293
|
-
rubygems_version: 3.5.
|
287
|
+
rubygems_version: 3.5.20
|
294
288
|
signing_key:
|
295
289
|
specification_version: 4
|
296
290
|
summary: A Ruby Interface file generator for gems, core types and the Ruby standard
|