Sha256: b3453fe9702a349d7ea4ea6e19c0a511fc163f98a16f176eec7a2cab90e4fa05

Contents?: true

Size: 874 Bytes

Versions: 1

Compression:

Stored size: 874 Bytes

Contents

$:.unshift File.dirname(__FILE__)

require 'reek/smells/smell'

module Reek
  module Smells

    #
    # A Large Class is a class or module that has a large number of
    # instance variables, methods or lines of code.
    # 
    # Currently +LargeClass+ only reports classes having more than
    # +MAX_ALLOWED+ public methods.
    #
    class LargeClass < Smell
      MAX_ALLOWED = 25

      def self.non_inherited_methods(klass)
        return klass.instance_methods if klass.superclass.nil?
        klass.instance_methods - klass.superclass.instance_methods
      end

      def recognise?(name)
        klass = Object.const_get(name) rescue return
        @num_methods = LargeClass.non_inherited_methods(klass).length
        @num_methods > MAX_ALLOWED
      end

      def detailed_report
        "#{@context} has #{@num_methods} methods"
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reek-0.3.1 lib/reek/smells/large_class.rb