Class: Reek::MethodGroup

Inherits:
Object show all
Defined in:
lib/reek/smells/data_clump.rb

Overview

Represents a group of methods

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, min_clump_size, max_copies) ⇒ MethodGroup

Returns a new instance of MethodGroup.



71
72
73
74
75
# File 'lib/reek/smells/data_clump.rb', line 71

def initialize(klass, min_clump_size, max_copies)
  @klass = klass
  @min_clump_size = min_clump_size
  @max_copies = max_copies
end

Class Method Details

.intersection_of_parameters_of(methods) ⇒ Object

:nodoc:



67
68
69
# File 'lib/reek/smells/data_clump.rb', line 67

def self.intersection_of_parameters_of(methods)
  methods.map {|meth| meth.parameters.names.sort}.intersection
end

Instance Method Details

#clumpsObject



77
78
79
80
81
82
83
84
85
86
# File 'lib/reek/smells/data_clump.rb', line 77

def clumps
  results = Hash.new(0)
  @klass.parameterized_methods(@min_clump_size).bounded_power_set(@max_copies).each do |methods|
    clump = MethodGroup.intersection_of_parameters_of(methods)
    if clump.length >= @min_clump_size
      results[clump] = [methods.length, results[clump]].max
    end
  end
  results
end