tapioca 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tapioca/cli.rb +1 -1
- data/lib/tapioca/compilers/dsl/active_record_associations.rb +1 -19
- data/lib/tapioca/compilers/dsl/active_record_columns.rb +14 -8
- data/lib/tapioca/compilers/requires_compiler.rb +4 -4
- data/lib/tapioca/compilers/symbol_table/symbol_generator.rb +6 -1
- data/lib/tapioca/version.rb +1 -1
- metadata +16 -3
- data/lib/tapioca/sorbet_config_parser.rb +0 -77
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9b10c318332131210706b023ccbe3a63a5889153e3b365a9c454ee7311d2498
|
4
|
+
data.tar.gz: 6c5a5ef82c6a952b535f6f04b3c3127968bca4d8d101e321e13e8e5968ea3222
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1df6d85dd2924d25e3d6460749cc5a5ce75022bf999e663c813d6dd483e130b6a1c9873872f2412046d6d15f87effc125bc2f3941323f0ac3eca27a0bfa89a7
|
7
|
+
data.tar.gz: f6b81c3d32e1cec689ed022c17f57ada8655c0594c944c396d26a481e32dce029b77ed8f877063bfee138405019f6bb5408f2de3148d437a2b8db01a699063c5
|
data/lib/tapioca/cli.rb
CHANGED
@@ -132,11 +132,7 @@ module Tapioca
|
|
132
132
|
end
|
133
133
|
def populate_single_assoc_getter_setter(klass, constant, association_name, reflection)
|
134
134
|
association_class = type_for(constant, reflection)
|
135
|
-
association_type =
|
136
|
-
association_class
|
137
|
-
else
|
138
|
-
"T.nilable(#{association_class})"
|
139
|
-
end
|
135
|
+
association_type = "T.nilable(#{association_class})"
|
140
136
|
|
141
137
|
create_method(
|
142
138
|
klass,
|
@@ -227,20 +223,6 @@ module Tapioca
|
|
227
223
|
)
|
228
224
|
end
|
229
225
|
|
230
|
-
sig do
|
231
|
-
params(
|
232
|
-
constant: T.class_of(ActiveRecord::Base),
|
233
|
-
reflection: ReflectionType
|
234
|
-
).returns(T::Boolean)
|
235
|
-
end
|
236
|
-
def belongs_to_and_required?(constant, reflection)
|
237
|
-
return false unless constant.table_exists?
|
238
|
-
return false unless reflection.belongs_to?
|
239
|
-
column_definition = constant.columns_hash[reflection.foreign_key.to_s]
|
240
|
-
|
241
|
-
!column_definition.nil? && !column_definition.null
|
242
|
-
end
|
243
|
-
|
244
226
|
sig do
|
245
227
|
params(
|
246
228
|
constant: T.class_of(ActiveRecord::Base),
|
@@ -196,25 +196,25 @@ module Tapioca
|
|
196
196
|
klass,
|
197
197
|
"#{attribute_name}_before_last_save",
|
198
198
|
methods_to_add,
|
199
|
-
return_type: getter_type
|
199
|
+
return_type: as_nilable_type(getter_type)
|
200
200
|
)
|
201
201
|
add_method(
|
202
202
|
klass,
|
203
203
|
"#{attribute_name}_change_to_be_saved",
|
204
204
|
methods_to_add,
|
205
|
-
return_type: "[#{getter_type}, #{getter_type}]"
|
205
|
+
return_type: "T.nilable([#{getter_type}, #{getter_type}])"
|
206
206
|
)
|
207
207
|
add_method(
|
208
208
|
klass,
|
209
209
|
"#{attribute_name}_in_database",
|
210
210
|
methods_to_add,
|
211
|
-
return_type: getter_type
|
211
|
+
return_type: as_nilable_type(getter_type)
|
212
212
|
)
|
213
213
|
add_method(
|
214
214
|
klass,
|
215
215
|
"saved_change_to_#{attribute_name}",
|
216
216
|
methods_to_add,
|
217
|
-
return_type: "[#{getter_type}, #{getter_type}]"
|
217
|
+
return_type: "T.nilable([#{getter_type}, #{getter_type}])"
|
218
218
|
)
|
219
219
|
add_method(
|
220
220
|
klass,
|
@@ -235,7 +235,7 @@ module Tapioca
|
|
235
235
|
klass,
|
236
236
|
"#{attribute_name}_change",
|
237
237
|
methods_to_add,
|
238
|
-
return_type: "[#{getter_type}, #{getter_type}]"
|
238
|
+
return_type: "T.nilable([#{getter_type}, #{getter_type}])"
|
239
239
|
)
|
240
240
|
add_method(
|
241
241
|
klass,
|
@@ -252,13 +252,13 @@ module Tapioca
|
|
252
252
|
klass,
|
253
253
|
"#{attribute_name}_was",
|
254
254
|
methods_to_add,
|
255
|
-
return_type: getter_type
|
255
|
+
return_type: as_nilable_type(getter_type)
|
256
256
|
)
|
257
257
|
add_method(
|
258
258
|
klass,
|
259
259
|
"#{attribute_name}_previous_change",
|
260
260
|
methods_to_add,
|
261
|
-
return_type: "[#{getter_type}, #{getter_type}]"
|
261
|
+
return_type: "T.nilable([#{getter_type}, #{getter_type}])"
|
262
262
|
)
|
263
263
|
add_method(
|
264
264
|
klass,
|
@@ -270,7 +270,7 @@ module Tapioca
|
|
270
270
|
klass,
|
271
271
|
"#{attribute_name}_previously_was",
|
272
272
|
methods_to_add,
|
273
|
-
return_type: getter_type
|
273
|
+
return_type: as_nilable_type(getter_type)
|
274
274
|
)
|
275
275
|
add_method(
|
276
276
|
klass,
|
@@ -381,6 +381,12 @@ module Tapioca
|
|
381
381
|
|
382
382
|
arg_type.to_s
|
383
383
|
end
|
384
|
+
|
385
|
+
sig { params(type: String).returns(String) }
|
386
|
+
def as_nilable_type(type)
|
387
|
+
return type if type.start_with?("T.nilable(")
|
388
|
+
"T.nilable(#{type})"
|
389
|
+
end
|
384
390
|
end
|
385
391
|
end
|
386
392
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
# typed: strict
|
3
3
|
|
4
|
-
|
4
|
+
require 'spoom'
|
5
5
|
|
6
6
|
module Tapioca
|
7
7
|
module Compilers
|
@@ -15,7 +15,7 @@ module Tapioca
|
|
15
15
|
|
16
16
|
sig { returns(String) }
|
17
17
|
def compile
|
18
|
-
config =
|
18
|
+
config = Spoom::Sorbet::Config.parse_file(@sorbet_path)
|
19
19
|
files = collect_files(config)
|
20
20
|
files.flat_map do |file|
|
21
21
|
collect_requires(file).reject do |req|
|
@@ -28,7 +28,7 @@ module Tapioca
|
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
|
-
sig { params(config:
|
31
|
+
sig { params(config: Spoom::Sorbet::Config).returns(T::Array[String]) }
|
32
32
|
def collect_files(config)
|
33
33
|
config.paths.flat_map do |path|
|
34
34
|
path = (Pathname.new(@sorbet_path) / "../.." / path).cleanpath
|
@@ -49,7 +49,7 @@ module Tapioca
|
|
49
49
|
end.compact
|
50
50
|
end
|
51
51
|
|
52
|
-
sig { params(config:
|
52
|
+
sig { params(config: Spoom::Sorbet::Config, file: String).returns(T::Boolean) }
|
53
53
|
def file_ignored_by_sorbet?(config, file)
|
54
54
|
config.ignore.any? do |path|
|
55
55
|
Regexp.new(Regexp.escape(path)) =~ file
|
@@ -565,7 +565,7 @@ module Tapioca
|
|
565
565
|
params << [signature.block_name, signature.block_type] if signature.block_name
|
566
566
|
|
567
567
|
params = params.compact.map { |name, type| "#{name}: #{type}" }.join(", ")
|
568
|
-
returns = signature.return_type
|
568
|
+
returns = type_of(signature.return_type)
|
569
569
|
|
570
570
|
type_parameters = (params + returns).scan(TYPE_PARAMETER_MATCHER).flatten.uniq.map { |p| ":#{p}" }.join(", ")
|
571
571
|
type_parameters = ".type_parameters(#{type_parameters})" unless type_parameters.empty?
|
@@ -784,6 +784,11 @@ module Tapioca
|
|
784
784
|
nil
|
785
785
|
end
|
786
786
|
|
787
|
+
sig { params(constant: Module).returns(String) }
|
788
|
+
def type_of(constant)
|
789
|
+
constant.to_s.gsub(/\bAttachedClass\b/, "T.attached_class")
|
790
|
+
end
|
791
|
+
|
787
792
|
sig { params(constant: Module, other: BasicObject).returns(T::Boolean).checked(:never) }
|
788
793
|
def are_equal?(constant, other)
|
789
794
|
BasicObject.instance_method(:equal?).bind(constant).call(other)
|
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.4
|
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: 2020-08-
|
14
|
+
date: 2020-08-26 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: pry
|
@@ -69,6 +69,20 @@ dependencies:
|
|
69
69
|
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: 2.1.0
|
72
|
+
- !ruby/object:Gem::Dependency
|
73
|
+
name: spoom
|
74
|
+
requirement: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
type: :runtime
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
72
86
|
- !ruby/object:Gem::Dependency
|
73
87
|
name: thor
|
74
88
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,7 +141,6 @@ files:
|
|
127
141
|
- lib/tapioca/gemfile.rb
|
128
142
|
- lib/tapioca/generator.rb
|
129
143
|
- lib/tapioca/loader.rb
|
130
|
-
- lib/tapioca/sorbet_config_parser.rb
|
131
144
|
- lib/tapioca/version.rb
|
132
145
|
homepage: https://github.com/Shopify/tapioca
|
133
146
|
licenses:
|
@@ -1,77 +0,0 @@
|
|
1
|
-
# typed: strict
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
module Tapioca
|
5
|
-
class SorbetConfig
|
6
|
-
extend T::Sig
|
7
|
-
|
8
|
-
sig { returns(T::Array[String]) }
|
9
|
-
attr_reader :paths, :ignore
|
10
|
-
|
11
|
-
sig { void }
|
12
|
-
def initialize
|
13
|
-
@paths = T.let([], T::Array[String])
|
14
|
-
@ignore = T.let([], T::Array[String])
|
15
|
-
end
|
16
|
-
|
17
|
-
class << self
|
18
|
-
extend T::Sig
|
19
|
-
|
20
|
-
sig { params(sorbet_config_path: String).returns(SorbetConfig) }
|
21
|
-
def parse_file(sorbet_config_path)
|
22
|
-
parse_string(File.read(sorbet_config_path))
|
23
|
-
end
|
24
|
-
|
25
|
-
sig { params(sorbet_config: String).returns(SorbetConfig) }
|
26
|
-
def parse_string(sorbet_config)
|
27
|
-
config = SorbetConfig.new
|
28
|
-
ignore = T.let(false, T::Boolean)
|
29
|
-
skip = T.let(false, T::Boolean)
|
30
|
-
sorbet_config.each_line do |line|
|
31
|
-
line = line.strip
|
32
|
-
case line
|
33
|
-
when /^--ignore$/
|
34
|
-
ignore = true
|
35
|
-
next
|
36
|
-
when /^--ignore=/
|
37
|
-
config.ignore << parse_option(line)
|
38
|
-
next
|
39
|
-
when /^--file$/
|
40
|
-
next
|
41
|
-
when /^--file=/
|
42
|
-
config.paths << parse_option(line)
|
43
|
-
next
|
44
|
-
when /^--dir$/
|
45
|
-
next
|
46
|
-
when /^--dir=/
|
47
|
-
config.paths << parse_option(line)
|
48
|
-
next
|
49
|
-
when /^--.*=/
|
50
|
-
next
|
51
|
-
when /^--/
|
52
|
-
skip = true
|
53
|
-
when /^-.*=?/
|
54
|
-
next
|
55
|
-
else
|
56
|
-
if ignore
|
57
|
-
config.ignore << line
|
58
|
-
ignore = false
|
59
|
-
elsif skip
|
60
|
-
skip = false
|
61
|
-
else
|
62
|
-
config.paths << line
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
config
|
67
|
-
end
|
68
|
-
|
69
|
-
private
|
70
|
-
|
71
|
-
sig { params(line: String).returns(String) }
|
72
|
-
def parse_option(line)
|
73
|
-
T.must(line.split("=").last).strip
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|