Sha256: 62d334d2548b27cb33b705033b141194a0162af657b719a5ea2035e90d3514a3

Contents?: true

Size: 971 Bytes

Versions: 6

Compression:

Stored size: 971 Bytes

Contents

require 'rubygems'
require 'sexp_processor'

module Reek

  class ObjectRefs  # :nodoc:
    def initialize
      @refs = Hash.new(0)
      record_reference_to_self
    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

    # TODO
    # Should be moved to Hash; but Hash has 58 methods, and there's currently
    # no way to turn off that report; which would therefore make the tests fail
    def max_keys
      max = max_refs
      @refs.reject {|key,val| val != max}.keys
    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

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
kevinrutherford-reek-0.3.1.4 lib/reek/object_refs.rb
kevinrutherford-reek-0.3.1.5 lib/reek/object_refs.rb
kevinrutherford-reek-0.3.1.6 lib/reek/object_refs.rb
kevinrutherford-reek-1.0.0 lib/reek/object_refs.rb
kevinrutherford-reek-1.0.1 lib/reek/object_refs.rb
reek-1.0.0 lib/reek/object_refs.rb