sorbet_erb 0.7.0 → 0.8.0
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/lib/sorbet_erb/code_extractor.rb +14 -3
- data/lib/sorbet_erb/version.rb +1 -1
- data/lib/sorbet_erb.rb +3 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 25b649fa14f8cd5c9c373f45cea41a69fc2b72816797ac8d0e4139fa34c68552
|
|
4
|
+
data.tar.gz: badb349a3451f624893b2a84d98fbc00e54c4026681fe79c29ec5a6a0d49b02f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f41374fe338f5898ec1da435aae7d2b0d0a71331e8d85bf8a32c429bd924c815f67c189addc0d149ccfd6e85cc96e7f620ad8c43ebeded32ab20949851c71feb
|
|
7
|
+
data.tar.gz: 83f58df8ad5d727f748e0cb7ca02be664872ac93267fc4027ef6e721f0c3d864827f250436c0923f6efec530bb5f8099d5e705456500e3682c0d567f5a73fca4
|
|
@@ -9,7 +9,11 @@ module SorbetErb
|
|
|
9
9
|
class CodeExtractor
|
|
10
10
|
extend T::Sig
|
|
11
11
|
|
|
12
|
-
sig
|
|
12
|
+
sig do
|
|
13
|
+
params(input: String).returns(
|
|
14
|
+
[T::Array[String], T.nilable(String), T.nilable(String), T.nilable(String)]
|
|
15
|
+
)
|
|
16
|
+
end
|
|
13
17
|
def extract(input)
|
|
14
18
|
buffer = Parser::Source::Buffer.new('(buffer)')
|
|
15
19
|
buffer.source = input
|
|
@@ -17,7 +21,7 @@ module SorbetErb
|
|
|
17
21
|
|
|
18
22
|
p = CodeProcessor.new
|
|
19
23
|
p.process(parser.ast)
|
|
20
|
-
[p.output, p.locals, p.locals_sig]
|
|
24
|
+
[p.output, p.locals, p.locals_sig, p.controller_class]
|
|
21
25
|
end
|
|
22
26
|
end
|
|
23
27
|
|
|
@@ -27,6 +31,7 @@ module SorbetErb
|
|
|
27
31
|
|
|
28
32
|
LOCALS_PREFIX = 'locals:'
|
|
29
33
|
LOCALS_SIG_PREFIX = 'locals_sig:'
|
|
34
|
+
CONTROLLER_CLASS_PREFIX = 'controller_class:'
|
|
30
35
|
|
|
31
36
|
sig { returns(T::Array[String]) }
|
|
32
37
|
attr_accessor :output
|
|
@@ -37,11 +42,15 @@ module SorbetErb
|
|
|
37
42
|
sig { returns(T.nilable(String)) }
|
|
38
43
|
attr_accessor :locals_sig
|
|
39
44
|
|
|
45
|
+
sig { returns(T.nilable(String)) }
|
|
46
|
+
attr_accessor :controller_class
|
|
47
|
+
|
|
40
48
|
sig { void }
|
|
41
49
|
def initialize
|
|
42
50
|
@output = T.let([], T::Array[String])
|
|
43
51
|
@locals = T.let(nil, T.nilable(String))
|
|
44
52
|
@locals_sig = T.let(nil, T.nilable(String))
|
|
53
|
+
@controller_class = T.let(nil, T.nilable(String))
|
|
45
54
|
end
|
|
46
55
|
|
|
47
56
|
sig { params(node: AST::Node).void }
|
|
@@ -61,13 +70,15 @@ module SorbetErb
|
|
|
61
70
|
indicator = indicator_node.children.first
|
|
62
71
|
case indicator
|
|
63
72
|
when '#'
|
|
64
|
-
# Ignore comments
|
|
73
|
+
# Ignore comments unless they declare a recognized annotation.
|
|
65
74
|
code_text = code_node.children.first.strip
|
|
66
75
|
if code_text.start_with?(LOCALS_PREFIX)
|
|
67
76
|
# No need to parse the locals
|
|
68
77
|
@locals = code_text.delete_prefix(LOCALS_PREFIX).strip
|
|
69
78
|
elsif code_text.start_with?(LOCALS_SIG_PREFIX)
|
|
70
79
|
@locals_sig = code_text.delete_prefix(LOCALS_SIG_PREFIX).strip
|
|
80
|
+
elsif code_text.start_with?(CONTROLLER_CLASS_PREFIX)
|
|
81
|
+
@controller_class = code_text.delete_prefix(CONTROLLER_CLASS_PREFIX).strip
|
|
71
82
|
end
|
|
72
83
|
else
|
|
73
84
|
process_all(node.children)
|
data/lib/sorbet_erb/version.rb
CHANGED
data/lib/sorbet_erb.rb
CHANGED
|
@@ -90,7 +90,7 @@ module SorbetErb
|
|
|
90
90
|
next if exclude_paths.any? { |excluded| pathname.to_s.include?(excluded) }
|
|
91
91
|
|
|
92
92
|
extractor = CodeExtractor.new
|
|
93
|
-
lines, locals, locals_sig = extractor.extract(File.read(p))
|
|
93
|
+
lines, locals, locals_sig, controller_class = extractor.extract(File.read(p))
|
|
94
94
|
|
|
95
95
|
# Partials and Turbo streams must use strict locals
|
|
96
96
|
next if requires_defined_locals?(pathname.basename.to_s) && locals.nil? && skip_missing_locals
|
|
@@ -99,6 +99,7 @@ module SorbetErb
|
|
|
99
99
|
locals_sig ||= ''
|
|
100
100
|
|
|
101
101
|
class_name, extend_app_controller = class_name_from_path(pathname)
|
|
102
|
+
parent_class = controller_class || config.app_controller_class
|
|
102
103
|
|
|
103
104
|
rel_output_dir = File.join(
|
|
104
105
|
output_dir,
|
|
@@ -114,7 +115,7 @@ module SorbetErb
|
|
|
114
115
|
File.open(output_path, 'w') do |f|
|
|
115
116
|
result = erb.result_with_hash(
|
|
116
117
|
class_name: class_name,
|
|
117
|
-
class_decl_suffix: extend_app_controller ? " < #{
|
|
118
|
+
class_decl_suffix: extend_app_controller ? " < #{parent_class}" : '',
|
|
118
119
|
locals: locals,
|
|
119
120
|
locals_sig: locals_sig,
|
|
120
121
|
extra_includes: config.extra_includes,
|