Sha256: 138c21123a60373a84ccf88547bd8b7e155cb47248ba5dd17b0465782743c228

Contents?: true

Size: 690 Bytes

Versions: 3

Compression:

Stored size: 690 Bytes

Contents

module Reek
  # @api private
  module AST
    ObjectRef = Struct.new(:name, :line)
    #
    # Manages and counts the references out of a method to other objects.
    #
    class ObjectRefs
      def initialize
        @refs = Hash.new { |refs, name| refs[name] = [] }
      end

      def most_popular
        max = @refs.values.map(&:size).max
        @refs.select { |_name, refs| refs.size == max }
      end

      def record_reference_to(name, line: nil)
        @refs[name] << ObjectRef.new(name, line)
      end

      def references_to(name)
        @refs[name]
      end

      def self_is_max?
        @refs.empty? || most_popular.keys.include?(:self)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reek-3.2.1 lib/reek/ast/object_refs.rb
reek-3.1 lib/reek/ast/object_refs.rb
reek-3.0.4 lib/reek/ast/object_refs.rb