@@ -10,13 +10,10 @@ class ConstNodeInspector
10
10
11
11
def constant_name_from_node ( node , ancestors :)
12
12
return nil unless Node . constant? ( node )
13
-
14
- # Only process the root `const` node for namespaced constant references. For example, in the
15
- # reference `Spam::Eggs::Thing`, we only process the const node associated with `Spam`.
16
13
parent = ancestors . first
17
- return nil if parent && Node . constant ?( parent )
14
+ return nil unless root_constant ?( parent )
18
15
19
- if constant_in_module_or_class_definition? ( node , parent : parent )
16
+ if parent && constant_in_module_or_class_definition? ( node , parent : parent )
20
17
fully_qualify_constant ( node , ancestors : ancestors )
21
18
else
22
19
begin
@@ -29,11 +26,15 @@ def constant_name_from_node(node, ancestors:)
29
26
30
27
private
31
28
29
+ # Only process the root `const` node for namespaced constant references. For example, in the
30
+ # reference `Spam::Eggs::Thing`, we only process the const node associated with `Spam`.
31
+ def root_constant? ( parent )
32
+ !( parent && Node . constant? ( parent ) )
33
+ end
34
+
32
35
def constant_in_module_or_class_definition? ( node , parent :)
33
- if parent
34
- parent_name = Node . module_name_from_definition ( parent )
35
- parent_name && parent_name == Node . constant_name ( node )
36
- end
36
+ parent_name = Node . module_name_from_definition ( parent )
37
+ parent_name && parent_name == Node . constant_name ( node )
37
38
end
38
39
39
40
def fully_qualify_constant ( node , ancestors :)
0 commit comments