Sha256: 3e4aae19ad678a9436eeb0f090e36923fef0ad48ebbb407e34ceb3c78fa42156
Contents?: true
Size: 986 Bytes
Versions: 2
Compression:
Stored size: 986 Bytes
Contents
$:.unshift File.dirname(__FILE__) require 'rubygems' require 'sexp' require 'reek/printer' module Reek class ObjectRefs SELF_REF = Sexp.from_array([:lit, :self]) 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 {|k,v| v != max}.keys end def self_is_max? max_keys.length == 0 || @refs[SELF_REF] == max_refs end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
reek-0.3.0 | lib/reek/object_refs.rb |
reek-0.2.3 | lib/reek/object_refs.rb |