Sha256: f66333e8fed17cfc4047676c764a3e4054f9bc9c11bd877b19757ef9b175c00a

Contents?: true

Size: 739 Bytes

Versions: 11

Compression:

Stored size: 739 Bytes

Contents

require 'private_attr/everywhere'

module Reek
  module AST
    #
    # Locates references to the current object within a portion
    # of an abstract syntax tree.
    #
    class ReferenceCollector
      STOP_NODES = [:class, :module, :def, :defs]

      def initialize(ast)
        @ast = ast
      end

      def num_refs_to_self
        (explicit_self_calls + implicit_self_calls).size
      end

      private

      private_attr_reader :ast

      def explicit_self_calls
        [:self, :super, :zsuper, :ivar, :ivasgn].flat_map do |node_type|
          ast.each_node(node_type, STOP_NODES)
        end
      end

      def implicit_self_calls
        ast.each_node(:send, STOP_NODES).reject(&:receiver)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
reek-3.10.1 lib/reek/ast/reference_collector.rb
reek-3.10.0 lib/reek/ast/reference_collector.rb
reek-3.9.1 lib/reek/ast/reference_collector.rb
reek-3.9.0 lib/reek/ast/reference_collector.rb
reek-3.8.3 lib/reek/ast/reference_collector.rb
reek-3.8.2 lib/reek/ast/reference_collector.rb
reek-3.8.1 lib/reek/ast/reference_collector.rb
reek-3.8.0 lib/reek/ast/reference_collector.rb
reek-3.7.1 lib/reek/ast/reference_collector.rb
reek-3.7.0 lib/reek/ast/reference_collector.rb
reek-3.6.1 lib/reek/ast/reference_collector.rb