Class: Reek::DetectorRepository
- Inherits:
-
Object
- Object
- Reek::DetectorRepository
- Defined in:
- lib/reek/detector_repository.rb
Overview
Contains all the existing smell detectors and exposes operations on them.
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
private
Returns the value of attribute configuration.
-
#smell_types ⇒ Object
readonly
private
Returns the value of attribute smell_types.
Class Method Summary collapse
-
.available_detector_names ⇒ Array<String>
The names of all known SmellDetectors e.g.
-
.eligible_smell_types(filter_by_smells = []) ⇒ Array<Reek::SmellDetectors::BaseDetector>
All SmellDetectors that we want to filter for e.g.
-
.smell_types ⇒ Array<Reek::SmellDetectors::BaseDetector>
All known SmellDetectors e.g.
Instance Method Summary collapse
- #configuration_for(klass) ⇒ Object private
- #examine(context) ⇒ Object
-
#initialize(smell_types: self.class.smell_types, configuration: {}) ⇒ DetectorRepository
constructor
A new instance of DetectorRepository.
- #smell_detectors_for(type) ⇒ Object private
Constructor Details
#initialize(smell_types: self.class.smell_types, configuration: {}) ⇒ DetectorRepository
Returns a new instance of DetectorRepository.
35 36 37 38 39 |
# File 'lib/reek/detector_repository.rb', line 35 def initialize(smell_types: self.class.smell_types, configuration: {}) @configuration = configuration @smell_types = smell_types end |
Instance Attribute Details
#configuration ⇒ Object (readonly, private)
Returns the value of attribute configuration.
56 57 58 |
# File 'lib/reek/detector_repository.rb', line 56 def configuration @configuration end |
#smell_types ⇒ Object (readonly, private)
Returns the value of attribute smell_types.
56 57 58 |
# File 'lib/reek/detector_repository.rb', line 56 def smell_types @smell_types end |
Class Method Details
.available_detector_names ⇒ Array<String>
Returns The names of all known SmellDetectors e.g. [“BooleanParameter”, “ClassVariable”].
50 51 52 |
# File 'lib/reek/detector_repository.rb', line 50 def self.available_detector_names smell_types.map(&:smell_type) end |
.eligible_smell_types(filter_by_smells = []) ⇒ Array<Reek::SmellDetectors::BaseDetector>
Returns All SmellDetectors that we want to filter for e.g. [Reek::SmellDetectors::Attribute].
27 28 29 30 31 32 33 |
# File 'lib/reek/detector_repository.rb', line 27 def self.eligible_smell_types(filter_by_smells = []) return smell_types if filter_by_smells.empty? smell_types.select do |klass| filter_by_smells.include? klass.smell_type end end |
.smell_types ⇒ Array<Reek::SmellDetectors::BaseDetector>
Returns All known SmellDetectors e.g. [Reek::SmellDetectors::BooleanParameter, Reek::SmellDetectors::ClassVariable].
14 15 16 |
# File 'lib/reek/detector_repository.rb', line 14 def self.smell_types Reek::SmellDetectors::BaseDetector.descendants.sort_by(&:name) end |
Instance Method Details
#configuration_for(klass) ⇒ Object (private)
58 59 60 |
# File 'lib/reek/detector_repository.rb', line 58 def configuration_for(klass) configuration.fetch klass, {} end |
#examine(context) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/reek/detector_repository.rb', line 41 def examine(context) smell_detectors_for(context.type).flat_map do |klass| detector = klass.new configuration: configuration_for(klass), context: context detector.run end end |
#smell_detectors_for(type) ⇒ Object (private)
62 63 64 |
# File 'lib/reek/detector_repository.rb', line 62 def smell_detectors_for(type) smell_types.select { |detector| detector.contexts.include? type } end |