Class: Reek::Source::ReferenceCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/reek/source/reference_collector.rb

Overview

Locates references to the current object within a portion of an abstract syntax tree.

Constant Summary collapse

STOP_NODES =
[:class, :module, :def, :defs]

Instance Method Summary collapse

Constructor Details

#initialize(ast) ⇒ ReferenceCollector

Returns a new instance of ReferenceCollector


11
12
13
# File 'lib/reek/source/reference_collector.rb', line 11

def initialize(ast)
  @ast = ast
end

Instance Method Details

#num_refs_to_selfObject


15
16
17
18
19
20
21
22
23
24
# File 'lib/reek/source/reference_collector.rb', line 15

def num_refs_to_self
  result = 0
  [:self, :zsuper, :ivar, :ivasgn].each do |node_type|
    @ast.look_for(node_type, STOP_NODES) { result += 1 }
  end
  @ast.look_for(:send, STOP_NODES) do |call|
    result += 1 unless call.receiver
  end
  result
end