Sha256: a4ad2133676977333dacdce9804af0dc7fc1a2057f3da00c30eabf196a20a817

Contents?: true

Size: 733 Bytes

Versions: 23

Compression:

Stored size: 733 Bytes

Contents

# frozen_string_literal: true
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].freeze

      def initialize(ast)
        @ast = ast
      end

      def num_refs_to_self
        (explicit_self_calls + implicit_self_calls).size
      end

      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

23 entries across 23 versions & 1 rubygems

Version Path
reek-4.5.3 lib/reek/ast/reference_collector.rb
reek-4.5.2 lib/reek/ast/reference_collector.rb
reek-4.5.1 lib/reek/ast/reference_collector.rb
reek-4.5.0 lib/reek/ast/reference_collector.rb
reek-4.4.2 lib/reek/ast/reference_collector.rb
reek-4.4.1 lib/reek/ast/reference_collector.rb
reek-4.4.0 lib/reek/ast/reference_collector.rb
reek-4.3.0 lib/reek/ast/reference_collector.rb
reek-4.2.5 lib/reek/ast/reference_collector.rb
reek-4.2.4 lib/reek/ast/reference_collector.rb
reek-4.2.3 lib/reek/ast/reference_collector.rb
reek-4.2.2 lib/reek/ast/reference_collector.rb
reek-4.2.1 lib/reek/ast/reference_collector.rb
reek-4.2.0 lib/reek/ast/reference_collector.rb
reek-4.1.1 lib/reek/ast/reference_collector.rb
reek-4.1.0 lib/reek/ast/reference_collector.rb
reek-4.0.5 lib/reek/ast/reference_collector.rb
reek-4.0.4 lib/reek/ast/reference_collector.rb
reek-4.0.3 lib/reek/ast/reference_collector.rb
reek-4.0.2 lib/reek/ast/reference_collector.rb