Class: Reek::Smells::LongMethod
- Inherits:
-
SmellDetector
- Object
- SmellDetector
- Reek::Smells::LongMethod
- Defined in:
- lib/reek/smells/long_method.rb
Overview
A Long Method is any method that has a large number of lines.
Currently LongMethod
reports any method with more than 5 statements.
Constant Summary collapse
- MAX_ALLOWED_STATEMENTS_KEY =
The name of the config field that sets the maximum number of statements permitted in any method.
'max_statements'
- DEFAULT_MAX_STATEMENTS =
5
Constants inherited from SmellDetector
SmellDetector::DEFAULT_EXCLUDE_SET, SmellDetector::EXCLUDE_KEY
Instance Attribute Summary collapse
-
#max_statements ⇒ Object
readonly
Returns the value of attribute max_statements.
Class Method Summary collapse
Instance Method Summary collapse
-
#examine_context(method) ⇒ Object
Checks the length of the given
method
. -
#initialize(config = LongMethod.default_config) ⇒ LongMethod
constructor
A new instance of LongMethod.
Methods inherited from SmellDetector
class_name, #configure, #configure_with, contexts, #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 = LongMethod.default_config) ⇒ LongMethod
Returns a new instance of LongMethod.
30 31 32 |
# File 'lib/reek/smells/long_method.rb', line 30 def initialize(config = LongMethod.default_config) super(config) end |
Instance Attribute Details
#max_statements ⇒ Object (readonly)
Returns the value of attribute max_statements.
28 29 30 |
# File 'lib/reek/smells/long_method.rb', line 28 def max_statements @max_statements end |
Class Method Details
.default_config ⇒ Object
21 22 23 24 25 26 |
# File 'lib/reek/smells/long_method.rb', line 21 def self.default_config super.adopt( MAX_ALLOWED_STATEMENTS_KEY => DEFAULT_MAX_STATEMENTS, EXCLUDE_KEY => ['initialize'] ) end |
Instance Method Details
#examine_context(method) ⇒ Object
Checks the length of the given method
. Remembers any smells found.
38 39 40 41 42 |
# File 'lib/reek/smells/long_method.rb', line 38 def examine_context(method) num = method.num_statements return false if num <= value(MAX_ALLOWED_STATEMENTS_KEY, method, DEFAULT_MAX_STATEMENTS) found(method, "has approx #{num} statements") end |