tapioca 0.4.7 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/tapioca/compilers/dsl/active_record_identity_cache.rb +1 -1
- data/lib/tapioca/compilers/dsl/base.rb +14 -10
- data/lib/tapioca/compilers/requires_compiler.rb +33 -5
- data/lib/tapioca/compilers/symbol_table/symbol_generator.rb +11 -4
- data/lib/tapioca/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f225f517eb2bb6e6d7aa6910bb42a35280b57ad8223dbd8bc255ce92377c6eb3
|
4
|
+
data.tar.gz: f3672f181cbcd71b9c8056c815e77313d75fcb2a78d2be5dbad3d2e51e35de39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcd0b9ebf36c2a467bb2e88cb91b1f0634cb772a3a5cf29f7dd3b716ddc3c4fd2ea4dd84b671df243255cc15651deb157d149578dde07f3f7eb26f0a8814a297
|
7
|
+
data.tar.gz: df7355fe19f05210797993286ead0f653a0f5b5f89263f469e8afece16d39026bde0cec1a0b266256ab236f43c27e95bd2912be3a9be74877ca6ca28037e09d7
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Tapioca
|
2
2
|
|
3
|
-
|
3
|
+
![Build Status](https://github.com/Shopify/tapioca/workflows/CI/badge.svg)
|
4
4
|
|
5
5
|
Tapioca is a library used to generate RBI (Ruby interface) files for use with [Sorbet](https://sorbet.org). RBI files provide the structure (classes, modules, methods, parameters) of the gem/library to Sorbet to assist with typechecking.
|
6
6
|
|
@@ -92,24 +92,28 @@ module Tapioca
|
|
92
92
|
method_def = signature.nil? ? method_def : signature.method
|
93
93
|
method_types = parameters_types_from_signature(method_def, signature)
|
94
94
|
|
95
|
-
method_def.parameters.each_with_index.map do |(type, name),
|
96
|
-
|
97
|
-
|
95
|
+
method_def.parameters.each_with_index.map do |(type, name), index|
|
96
|
+
fallback_arg_name = "_arg#{index}"
|
97
|
+
|
98
|
+
name ||= fallback_arg_name
|
99
|
+
name = name.to_s.gsub(/&|\*/, fallback_arg_name) # avoid incorrect names from `delegate`
|
100
|
+
method_type = method_types[index]
|
101
|
+
|
98
102
|
case type
|
99
103
|
when :req
|
100
|
-
::Parlour::RbiGenerator::Parameter.new(name, type:
|
104
|
+
::Parlour::RbiGenerator::Parameter.new(name, type: method_type)
|
101
105
|
when :opt
|
102
|
-
::Parlour::RbiGenerator::Parameter.new(name, type:
|
106
|
+
::Parlour::RbiGenerator::Parameter.new(name, type: method_type, default: 'T.unsafe(nil)')
|
103
107
|
when :rest
|
104
|
-
::Parlour::RbiGenerator::Parameter.new("*#{name}", type:
|
108
|
+
::Parlour::RbiGenerator::Parameter.new("*#{name}", type: method_type)
|
105
109
|
when :keyreq
|
106
|
-
::Parlour::RbiGenerator::Parameter.new("#{name}:", type:
|
110
|
+
::Parlour::RbiGenerator::Parameter.new("#{name}:", type: method_type)
|
107
111
|
when :key
|
108
|
-
::Parlour::RbiGenerator::Parameter.new("#{name}:", type:
|
112
|
+
::Parlour::RbiGenerator::Parameter.new("#{name}:", type: method_type, default: 'T.unsafe(nil)')
|
109
113
|
when :keyrest
|
110
|
-
::Parlour::RbiGenerator::Parameter.new("**#{name}", type:
|
114
|
+
::Parlour::RbiGenerator::Parameter.new("**#{name}", type: method_type)
|
111
115
|
when :block
|
112
|
-
::Parlour::RbiGenerator::Parameter.new("&#{name}", type:
|
116
|
+
::Parlour::RbiGenerator::Parameter.new("&#{name}", type: method_type)
|
113
117
|
else
|
114
118
|
raise "Unknown type `#{type}`."
|
115
119
|
end
|
@@ -34,7 +34,8 @@ module Tapioca
|
|
34
34
|
path = (Pathname.new(@sorbet_path) / "../.." / path).cleanpath
|
35
35
|
if path.directory?
|
36
36
|
Dir.glob("#{path}/**/*.rb", File::FNM_EXTGLOB).reject do |file|
|
37
|
-
|
37
|
+
relative_file_path = Pathname.new(file).relative_path_from(path)
|
38
|
+
file_ignored_by_sorbet?(config, relative_file_path)
|
38
39
|
end
|
39
40
|
else
|
40
41
|
[path.to_s]
|
@@ -49,13 +50,40 @@ module Tapioca
|
|
49
50
|
end.compact
|
50
51
|
end
|
51
52
|
|
52
|
-
sig { params(config: Spoom::Sorbet::Config,
|
53
|
-
def file_ignored_by_sorbet?(config,
|
54
|
-
|
55
|
-
|
53
|
+
sig { params(config: Spoom::Sorbet::Config, file_path: Pathname).returns(T::Boolean) }
|
54
|
+
def file_ignored_by_sorbet?(config, file_path)
|
55
|
+
file_path_parts = path_parts(file_path)
|
56
|
+
|
57
|
+
config.ignore.any? do |ignore|
|
58
|
+
# Sorbet --ignore matching method:
|
59
|
+
# ---
|
60
|
+
# Ignores input files that contain the given
|
61
|
+
# string in their paths (relative to the input
|
62
|
+
# path passed to Sorbet).
|
63
|
+
#
|
64
|
+
# Strings beginning with / match against the
|
65
|
+
# prefix of these relative paths; others are
|
66
|
+
# substring matchs.
|
67
|
+
|
68
|
+
# Matches must be against whole folder and file
|
69
|
+
# names, so `foo` matches `/foo/bar.rb` and
|
70
|
+
# `/bar/foo/baz.rb` but not `/foo.rb` or
|
71
|
+
# `/foo2/bar.rb`.
|
72
|
+
ignore_parts = path_parts(Pathname.new(ignore))
|
73
|
+
file_path_part_sequences = file_path_parts.each_cons(ignore_parts.size)
|
74
|
+
# if ignore string begins with /, we only want the first sequence to match
|
75
|
+
file_path_part_sequences = [file_path_part_sequences.first].to_enum if ignore.start_with?("/")
|
76
|
+
|
77
|
+
# we need to match whole segments
|
78
|
+
file_path_part_sequences.include?(ignore_parts)
|
56
79
|
end
|
57
80
|
end
|
58
81
|
|
82
|
+
sig { params(path: Pathname).returns(T::Array[String]) }
|
83
|
+
def path_parts(path)
|
84
|
+
T.unsafe(path).descend.map { |part| part.basename.to_s }
|
85
|
+
end
|
86
|
+
|
59
87
|
sig { params(files: T::Enumerable[String], name: String).returns(T::Boolean) }
|
60
88
|
def name_in_project?(files, name)
|
61
89
|
files.any? do |file|
|
@@ -209,7 +209,11 @@ module Tapioca
|
|
209
209
|
method = "const" if prop.fetch(:immutable, false)
|
210
210
|
type = prop.fetch(:type_object, "T.untyped")
|
211
211
|
|
212
|
-
|
212
|
+
if prop.key?(:default)
|
213
|
+
indented("#{method} :#{name}, #{type}, default: T.unsafe(nil)")
|
214
|
+
else
|
215
|
+
indented("#{method} :#{name}, #{type}")
|
216
|
+
end
|
213
217
|
end.join("\n")
|
214
218
|
end
|
215
219
|
|
@@ -513,7 +517,9 @@ module Tapioca
|
|
513
517
|
|
514
518
|
parameters = T.let(method.parameters, T::Array[[Symbol, T.nilable(Symbol)]])
|
515
519
|
|
516
|
-
sanitized_parameters = parameters.map do |type, name|
|
520
|
+
sanitized_parameters = parameters.each_with_index.map do |(type, name), index|
|
521
|
+
fallback_arg_name = "_arg#{index}"
|
522
|
+
|
517
523
|
unless name
|
518
524
|
# For attr_writer methods, Sorbet signatures have the name
|
519
525
|
# of the method (without the trailing = sign) as the name of
|
@@ -533,12 +539,12 @@ module Tapioca
|
|
533
539
|
name = if writer_method_with_sig
|
534
540
|
T.must(method_name[0...-1]).to_sym
|
535
541
|
else
|
536
|
-
|
542
|
+
fallback_arg_name
|
537
543
|
end
|
538
544
|
end
|
539
545
|
|
540
546
|
# Sanitize param names
|
541
|
-
name = name.to_s.gsub(/[^a-zA-Z0-9_]/,
|
547
|
+
name = name.to_s.gsub(/[^a-zA-Z0-9_]/, fallback_arg_name)
|
542
548
|
|
543
549
|
[type, name]
|
544
550
|
end
|
@@ -612,6 +618,7 @@ module Tapioca
|
|
612
618
|
signature_body = signature_body
|
613
619
|
.gsub(".returns(<VOID>)", ".void")
|
614
620
|
.gsub("<NOT-TYPED>", "T.untyped")
|
621
|
+
.gsub(".params()", "")
|
615
622
|
.gsub(TYPE_PARAMETER_MATCHER, "T.type_parameter(:\\1)")[1..-1]
|
616
623
|
|
617
624
|
"sig { #{signature_body} }"
|
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.8
|
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-
|
14
|
+
date: 2020-11-05 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: pry
|