view_component_devtools 0.1.0 → 0.1.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/lib/view_component_devtools/component.rb +39 -21
- data/lib/view_component_devtools/version.rb +1 -1
- 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: 133887ab12a90a7f356d8ab4c77475c53ac65e9280769060c1a02f6e9df6043e
|
|
4
|
+
data.tar.gz: fcf6a866579b6a27b71d40ac3c57d8453b76907e9520fb5b74cc03260985820b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9e79c04dd30cdcadb4c80a1dbf4f53410d17a95f2fdcffe4c27e03e98cd718705e89ee56de1f8c82a8a65e784cae21b86b7a0dacdb07dc4e8f95d99a2cdbae09
|
|
7
|
+
data.tar.gz: cbb037a59de31c4d41fb7017d2231f1e58660031f1a8f6c422eda105cf7e00afb5174d5dd7d7df0810510875d704b64db28d925f001c9ce56ee8c3f238e44c97
|
|
@@ -13,39 +13,54 @@ module ViewComponentDevtools
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def view_component_devtools_prop_names
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
classes = component_class_chain
|
|
17
|
+
declared = classes.flat_map do |component_class|
|
|
18
|
+
component_class.instance_variable_get(:@view_component_devtools_props) || []
|
|
19
|
+
end
|
|
20
|
+
inferred = classes.flat_map do |component_class|
|
|
21
|
+
component_initializer(component_class)&.parameters&.filter_map do |kind, name|
|
|
22
|
+
name if %i[req opt keyreq key].include?(kind)
|
|
23
|
+
end || []
|
|
20
24
|
end
|
|
21
|
-
declared = @view_component_devtools_props || []
|
|
22
|
-
trusted = inherited + declared
|
|
23
25
|
|
|
24
|
-
(
|
|
25
|
-
prop_reader?(name,
|
|
26
|
+
(declared + inferred).uniq.select do |name|
|
|
27
|
+
prop_reader?(name, classes:, explicitly_declared: declared.include?(name))
|
|
26
28
|
end
|
|
27
29
|
end
|
|
28
30
|
|
|
29
31
|
private
|
|
30
32
|
|
|
31
|
-
def
|
|
32
|
-
|
|
33
|
+
def component_class_chain
|
|
34
|
+
boundary = defined?(ViewComponent::Base) && self < ViewComponent::Base ?
|
|
35
|
+
ViewComponent::Base : Object
|
|
36
|
+
classes = []
|
|
37
|
+
component_class = self
|
|
33
38
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
while component_class.is_a?(Class) && component_class != boundary
|
|
40
|
+
classes << component_class
|
|
41
|
+
component_class = component_class.superclass
|
|
37
42
|
end
|
|
38
|
-
|
|
43
|
+
|
|
44
|
+
classes
|
|
39
45
|
end
|
|
40
46
|
|
|
41
|
-
def
|
|
42
|
-
return
|
|
47
|
+
def component_initializer(component_class)
|
|
48
|
+
return unless component_class.private_instance_methods(false).include?(:initialize) ||
|
|
49
|
+
component_class.protected_instance_methods(false).include?(:initialize) ||
|
|
50
|
+
component_class.public_instance_methods(false).include?(:initialize)
|
|
43
51
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
initializer = component_class.instance_method(:initialize)
|
|
53
|
+
initializer if initializer.owner == component_class
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def prop_reader?(name, classes:, explicitly_declared:)
|
|
57
|
+
return false unless public_method_defined?(name)
|
|
58
|
+
|
|
59
|
+
method = instance_method(name)
|
|
60
|
+
callable_without_arguments = method.parameters.none? do |kind, _|
|
|
61
|
+
%i[req keyreq].include?(kind)
|
|
48
62
|
end
|
|
63
|
+
callable_without_arguments && (explicitly_declared || classes.include?(method.owner))
|
|
49
64
|
end
|
|
50
65
|
end
|
|
51
66
|
|
|
@@ -71,7 +86,10 @@ module ViewComponentDevtools
|
|
|
71
86
|
return identifier if identifier
|
|
72
87
|
end
|
|
73
88
|
|
|
74
|
-
self.class.
|
|
89
|
+
initializer = self.class.send(:component_class_chain).filter_map do |component_class|
|
|
90
|
+
self.class.send(:component_initializer, component_class)
|
|
91
|
+
end.first
|
|
92
|
+
initializer&.source_location&.join(":")
|
|
75
93
|
end
|
|
76
94
|
end
|
|
77
95
|
end
|