Sha256: c47398f052dbeea3609fb6c67d1f2e1d41fccb4941531898485905f3b28ed84b

Contents?: true

Size: 685 Bytes

Versions: 7

Compression:

Stored size: 685 Bytes

Contents

module Reek
  module AST
    #
    # Locates references to the current object within a portion
    # of an abstract syntax tree.
    #
    # @api private
    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

      def explicit_self_calls
        [:self, :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

7 entries across 7 versions & 1 rubygems

Version Path
reek-3.2.1 lib/reek/ast/reference_collector.rb
reek-3.1 lib/reek/ast/reference_collector.rb
reek-3.0.4 lib/reek/ast/reference_collector.rb
reek-3.0.3 lib/reek/ast/reference_collector.rb
reek-3.0.2 lib/reek/ast/reference_collector.rb
reek-3.0.1 lib/reek/ast/reference_collector.rb
reek-3.0.0 lib/reek/ast/reference_collector.rb