Sha256: 16fd9893689b4ed2fab84d4553e83244a28c99bac2f25940a86a336a9c47a3ff
Contents?: true
Size: 1.94 KB
Versions: 5
Compression:
Stored size: 1.94 KB
Contents
require 'reek/smells/smell_detector' require 'reek/smell_warning' 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 a # configurable number of methods or instance variables. The method count # includes public, protected and # private methods, and excludes methods inherited from superclasses or # included modules. # class LargeClass < SmellDetector # The name of the config field that sets the maximum number of methods # permitted in a class. MAX_ALLOWED_METHODS_KEY = 'max_methods' # The name of the config field that sets the maximum number of instance # variables permitted in a class. MAX_ALLOWED_IVARS_KEY = 'max_instance_variables' def self.contexts # :nodoc: [:class] end def self.default_config super.adopt( MAX_ALLOWED_METHODS_KEY => 25, MAX_ALLOWED_IVARS_KEY => 9, EXCLUDE_KEY => [] ) end def initialize(config = LargeClass.default_config) super @max_methods = config[MAX_ALLOWED_METHODS_KEY] @max_instance_variables = config[MAX_ALLOWED_IVARS_KEY] end def check_num_methods(klass) # :nodoc: count = klass.num_methods return if count <= @max_methods found(klass, "has at least #{count} methods") end def check_num_ivars(klass) # :nodoc: count = klass.variable_names.length return if count <= @max_instance_variables found(klass, "has at least #{count} instance variables") end # # Checks +klass+ for too many methods or too many instance variables. # Remembers any smells found. # def examine_context(klass) check_num_methods(klass) check_num_ivars(klass) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems