Sha256: 2d95e5aaddc2ad630844dad9b718f2b3e5bbf9e10199886c58c4ed5ea38ac2e0

Contents?: true

Size: 818 Bytes

Versions: 27

Compression:

Stored size: 818 Bytes

Contents

require 'rubygems'
require 'sexp_processor'

module Reek

  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

    # TODO
    # Should be moved to Hash
    #
    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

27 entries across 27 versions & 3 rubygems

Version Path
kevinrutherford-reek-1.1.1 lib/reek/object_refs.rb
kevinrutherford-reek-1.1.2.1 lib/reek/object_refs.rb
kevinrutherford-reek-1.1.2 lib/reek/object_refs.rb
kevinrutherford-reek-1.1.3.1 lib/reek/object_refs.rb
kevinrutherford-reek-1.1.3.10 lib/reek/object_refs.rb
kevinrutherford-reek-1.1.3.11 lib/reek/object_refs.rb
kevinrutherford-reek-1.1.3.12 lib/reek/object_refs.rb
kevinrutherford-reek-1.1.3.13 lib/reek/object_refs.rb
kevinrutherford-reek-1.1.3.14 lib/reek/object_refs.rb
kevinrutherford-reek-1.1.3.15 lib/reek/object_refs.rb
kevinrutherford-reek-1.1.3.16 lib/reek/object_refs.rb
kevinrutherford-reek-1.1.3.2 lib/reek/object_refs.rb
kevinrutherford-reek-1.1.3.3 lib/reek/object_refs.rb
kevinrutherford-reek-1.1.3.4 lib/reek/object_refs.rb
kevinrutherford-reek-1.1.3.5 lib/reek/object_refs.rb
kevinrutherford-reek-1.1.3.6 lib/reek/object_refs.rb
kevinrutherford-reek-1.1.3.7 lib/reek/object_refs.rb
kevinrutherford-reek-1.1.3.8 lib/reek/object_refs.rb
kevinrutherford-reek-1.1.3.9 lib/reek/object_refs.rb
kevinrutherford-reek-1.1.3 lib/reek/object_refs.rb