Class: ImproveYourCode::SmellDetectors::BaseDetector
- Inherits:
-
Object
- Object
- ImproveYourCode::SmellDetectors::BaseDetector
show all
- Defined in:
- lib/improve_your_code/smell_detectors/base_detector.rb
Constant Summary
collapse
- EXCLUDE_KEY =
'exclude'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of BaseDetector.
14
15
16
17
|
# File 'lib/improve_your_code/smell_detectors/base_detector.rb', line 14
def initialize(context:)
@config = SmellConfiguration.new(self.class.default_config)
@context = context
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
10
11
12
|
# File 'lib/improve_your_code/smell_detectors/base_detector.rb', line 10
def config
@config
end
|
Class Method Details
.configuration_keys ⇒ Object
108
109
110
|
# File 'lib/improve_your_code/smell_detectors/base_detector.rb', line 108
def configuration_keys
Set.new(default_config.keys.map(&:to_sym))
end
|
.contexts ⇒ Object
80
81
82
|
# File 'lib/improve_your_code/smell_detectors/base_detector.rb', line 80
def contexts
%i[def defs]
end
|
.descendants ⇒ Object
95
96
97
|
# File 'lib/improve_your_code/smell_detectors/base_detector.rb', line 95
def descendants
@descendants ||= []
end
|
.inherited(subclass) ⇒ Object
91
92
93
|
# File 'lib/improve_your_code/smell_detectors/base_detector.rb', line 91
def inherited(subclass)
descendants << subclass
end
|
.smell_type ⇒ Object
76
77
78
|
# File 'lib/improve_your_code/smell_detectors/base_detector.rb', line 76
def smell_type
@smell_type ||= name.split(/::/).last
end
|
.to_detector(detector_name) ⇒ Object
104
105
106
|
# File 'lib/improve_your_code/smell_detectors/base_detector.rb', line 104
def to_detector(detector_name)
SmellDetectors.const_get detector_name
end
|
.todo_configuration_for(smells) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/improve_your_code/smell_detectors/base_detector.rb', line 19
def self.todo_configuration_for(smells)
default_exclusions = default_config.fetch EXCLUDE_KEY
exclusions = default_exclusions + smells.map(&:context)
{ smell_type => { EXCLUDE_KEY => exclusions.uniq } }
end
|
.valid_detector?(detector) ⇒ Boolean
99
100
101
102
|
# File 'lib/improve_your_code/smell_detectors/base_detector.rb', line 99
def valid_detector?(detector)
descendants.map { |descendant| descendant.to_s.split('::').last }
.include?(detector)
end
|
Instance Method Details
#run ⇒ Object
26
27
28
|
# File 'lib/improve_your_code/smell_detectors/base_detector.rb', line 26
def run
sniff
end
|
#smell_type ⇒ Object
30
31
32
|
# File 'lib/improve_your_code/smell_detectors/base_detector.rb', line 30
def smell_type
self.class.smell_type
end
|