Sha256: 908724e2798ad477c452f798cec803469f71019a0d3b49b71b4fafd3cba2b8f6

Contents?: true

Size: 813 Bytes

Versions: 2

Compression:

Stored size: 813 Bytes

Contents

module Reek
  module Core

  #
  # Manages and counts the references out of a method to other objects.
  #
  class ObjectRefs  # :nodoc:
    def initialize
      @refs = Hash.new(0)
    end

    def record_reference_to_self
      record_ref(SELF_REF)
    end

    def record_ref(exp)
      type = exp[0]
      case type
      when :gvar
        return
      when :self
        record_reference_to_self
      else
        @refs[exp] += 1
      end
    end

    def refs_to_self
      @refs[SELF_REF]
    end

    def max_refs
      @refs.values.max or 0
    end

    def max_keys
      max = max_refs
      @refs.reject {|key,val| val != max}
    end

    def self_is_max?
      max_keys.length == 0 || @refs[SELF_REF] == max_refs
    end

  private

    SELF_REF = Sexp.from_array([:lit, :self])

  end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reek-1.2.7.1 lib/reek/core/object_refs.rb
reek-1.2.7 lib/reek/core/object_refs.rb