Class: Reek::Smells::LargeClass
- Inherits:
-
SmellDetector
- Object
- SmellDetector
- Reek::Smells::LargeClass
- Defined in:
- lib/reek/smells/large_class.rb
Overview
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.
Constant Summary collapse
- MAX_ALLOWED_METHODS_KEY =
The name of the config field that sets the maximum number of methods permitted in a class.
'max_methods'
- DEFAULT_MAX_METHODS =
25
- MAX_ALLOWED_IVARS_KEY =
The name of the config field that sets the maximum number of instance variables permitted in a class.
'max_instance_variables'
- DEFAULT_MAX_IVARS =
9
Constants inherited from SmellDetector
SmellDetector::DEFAULT_EXCLUDE_SET, SmellDetector::EXCLUDE_KEY
Class Method Summary collapse
Instance Method Summary collapse
-
#check_num_ivars(klass) ⇒ Object
:nodoc:.
-
#check_num_methods(klass) ⇒ Object
:nodoc:.
-
#examine_context(klass) ⇒ Object
Checks
klass
for too many methods or too many instance variables. -
#initialize(config = LargeClass.default_config) ⇒ LargeClass
constructor
A new instance of LargeClass.
Methods inherited from SmellDetector
class_name, #configure, #configure_with, #copy, create, #enabled?, #examine, #exception?, #found, #has_smell?, listen, #listen_to, #num_smells, #report_on, #smell_name, #smelly?, #supersede_with, #value
Constructor Details
#initialize(config = LargeClass.default_config) ⇒ LargeClass
Returns a new instance of LargeClass.
43 44 45 |
# File 'lib/reek/smells/large_class.rb', line 43 def initialize(config = LargeClass.default_config) super(config) end |
Class Method Details
.contexts ⇒ Object
:nodoc:
31 32 33 |
# File 'lib/reek/smells/large_class.rb', line 31 def self.contexts # :nodoc: [:class] end |
.default_config ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/reek/smells/large_class.rb', line 35 def self.default_config super.adopt( MAX_ALLOWED_METHODS_KEY => DEFAULT_MAX_METHODS, MAX_ALLOWED_IVARS_KEY => DEFAULT_MAX_IVARS, EXCLUDE_KEY => [] ) end |
Instance Method Details
#check_num_ivars(klass) ⇒ Object
:nodoc:
53 54 55 56 57 |
# File 'lib/reek/smells/large_class.rb', line 53 def check_num_ivars(klass) # :nodoc: count = klass.variable_names.length return if count <= value(MAX_ALLOWED_IVARS_KEY, klass, DEFAULT_MAX_IVARS) found(klass, "has at least #{count} instance variables") end |
#check_num_methods(klass) ⇒ Object
:nodoc:
47 48 49 50 51 |
# File 'lib/reek/smells/large_class.rb', line 47 def check_num_methods(klass) # :nodoc: count = klass.num_methods return if count <= value(MAX_ALLOWED_METHODS_KEY, klass, DEFAULT_MAX_METHODS) found(klass, "has at least #{count} methods") end |
#examine_context(klass) ⇒ Object
Checks klass
for too many methods or too many instance variables. Remembers any smells found.
63 64 65 66 |
# File 'lib/reek/smells/large_class.rb', line 63 def examine_context(klass) check_num_methods(klass) check_num_ivars(klass) end |