Class: RuboCop::Cop::DarkFinger::ModuleAncestorChainExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/cop/dark_finger/module_ancestor_chain_extractor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ ModuleAncestorChainExtractor

Returns a new instance of ModuleAncestorChainExtractor.



7
8
9
# File 'lib/rubocop/cop/dark_finger/module_ancestor_chain_extractor.rb', line 7

def initialize(node)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



5
6
7
# File 'lib/rubocop/cop/dark_finger/module_ancestor_chain_extractor.rb', line 5

def node
  @node
end

Instance Method Details

#performObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rubocop/cop/dark_finger/module_ancestor_chain_extractor.rb', line 11

def perform
  module_chain = [node.children.first.const_name]

  current_node = node
  while current_node.parent && current_node.parent.module_type?
    module_chain << current_node.parent.children.first.const_name
    current_node = current_node.parent
  end

  module_chain.reverse.join("::")
end