Class: Reek::Smells::TooManyInstanceVariables Private
- Inherits:
-
SmellDetector
- Object
- SmellDetector
- Reek::Smells::TooManyInstanceVariables
- Defined in:
- lib/reek/smells/too_many_instance_variables.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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 Too-Many-Instance-Variables for details.
Constant Summary collapse
- MAX_ALLOWED_IVARS_KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The name of the config field that sets the maximum number of instance variables permitted in a class.
'max_instance_variables'
- DEFAULT_MAX_IVARS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
9
Constants inherited from SmellDetector
SmellDetector::DEFAULT_EXCLUDE_SET, SmellDetector::EXCLUDE_KEY
Instance Attribute Summary
Attributes inherited from SmellDetector
Class Method Summary collapse
-
.contexts ⇒ Object
private
:nodoc:.
- .default_config ⇒ Object private
- .smell_category ⇒ Object private
Instance Method Summary collapse
-
#examine_context(ctx) ⇒ Array<SmellWarning>
private
Checks
klass
for too many instance variables.
Methods inherited from SmellDetector
#config_for, #configure_with, default_smell_category, descendants, #enabled?, #enabled_for?, #examine, #exception?, #initialize, #register, #report_on, #smell_category, smell_type, #smell_type, #value
Constructor Details
This class inherits a constructor from Reek::Smells::SmellDetector
Class Method Details
.contexts ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
:nodoc:
25 26 27 |
# File 'lib/reek/smells/too_many_instance_variables.rb', line 25 def self.contexts # :nodoc: [:class] end |
.default_config ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
29 30 31 32 33 34 |
# File 'lib/reek/smells/too_many_instance_variables.rb', line 29 def self.default_config super.merge( MAX_ALLOWED_IVARS_KEY => DEFAULT_MAX_IVARS, EXCLUDE_KEY => [] ) end |
.smell_category ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
21 22 23 |
# File 'lib/reek/smells/too_many_instance_variables.rb', line 21 def self.smell_category 'LargeClass' end |
Instance Method Details
#examine_context(ctx) ⇒ Array<SmellWarning>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks klass
for too many instance variables.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/reek/smells/too_many_instance_variables.rb', line 41 def examine_context(ctx) @max_allowed_ivars = value(MAX_ALLOWED_IVARS_KEY, ctx, DEFAULT_MAX_IVARS) count = ctx.local_nodes(:ivasgn).map { |ivasgn| ivasgn[1] }.uniq.length return [] if count <= @max_allowed_ivars [SmellWarning.new(self, context: ctx.full_name, lines: [ctx.exp.line], message: "has at least #{count} instance variables", parameters: { count: count })] end |