class Reek::SmellDetectors::TooManyInstanceVariables
A Large Class is a class or module that has a large number of instance variables, methods or lines of code.
+TooManyInstanceVariables’ reports classes having more than a configurable number of instance variables.
See {file:docs/Too-Many-Instance-Variables.md} for details.
Constants
- DEFAULT_MAX_IVARS
- MAX_ALLOWED_IVARS_KEY
-
The name of the config field that sets the maximum number of instance variables permitted in a class.
Public Class Methods
Source
# File lib/reek/smell_detectors/too_many_instance_variables.rb, line 21 def self.contexts [:class] end
Source
# File lib/reek/smell_detectors/too_many_instance_variables.rb, line 25 def self.default_config super.merge( MAX_ALLOWED_IVARS_KEY => DEFAULT_MAX_IVARS, EXCLUDE_KEY => []) end
Calls superclass method
Reek::SmellDetectors::BaseDetector::default_config
Public Instance Methods
Source
# File lib/reek/smell_detectors/too_many_instance_variables.rb, line 36 def sniff variables = context.local_nodes(:ivasgn, [:or_asgn]).map(&:name) count = variables.uniq.size return [] if count <= max_allowed_ivars [smell_warning( lines: [source_line], message: "has at least #{count} instance variables", parameters: { count: count })] end
Checks klass
for too many instance variables.
@return [Array<SmellWarning>]
Private Instance Methods
Source
# File lib/reek/smell_detectors/too_many_instance_variables.rb, line 49 def max_allowed_ivars value(MAX_ALLOWED_IVARS_KEY, context) end