Class: Pronto::ClangFormat::OffenceCategorizer::AbstractCategorizer
- Inherits:
-
Object
- Object
- Pronto::ClangFormat::OffenceCategorizer::AbstractCategorizer
- Defined in:
- lib/pronto/clang_format/offence_categorizer/abstract_categorizer.rb
Overview
base class to implement a chain of categorizers
Direct Known Subclasses
IncludesOrderCategorizer, IndentationCategorizer, MissingNewlineCategorizer, TrailingWhitespaceCategorizer, UnnecessaryNewlineCategorizer, UsingOrderCategorizer
Instance Method Summary collapse
-
#handle(offence) ⇒ Object
Tries to handle the offence using the current categorizer.
- #handle_current(_offence) ⇒ Object
-
#initialize(successor = nil) ⇒ AbstractCategorizer
constructor
A new instance of AbstractCategorizer.
Constructor Details
#initialize(successor = nil) ⇒ AbstractCategorizer
Returns a new instance of AbstractCategorizer.
6 7 8 |
# File 'lib/pronto/clang_format/offence_categorizer/abstract_categorizer.rb', line 6 def initialize(successor = nil) @successor = successor end |
Instance Method Details
#handle(offence) ⇒ Object
Tries to handle the offence using the current categorizer. If it couldn’t, it passes the offence to the next categorizer in the chain. If this is the last categorizer in the chain, it returns a generic message
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/pronto/clang_format/offence_categorizer/abstract_categorizer.rb', line 14 def handle(offence) current_result = handle_current offence if !current_result.nil? current_result elsif !@successor.nil? @successor.handle offence else # unahndled offence "Improper formatting. This should be rewritten as: \n" \ "```#{offence.affected_lines_after}```" end end |
#handle_current(_offence) ⇒ Object
26 27 28 29 |
# File 'lib/pronto/clang_format/offence_categorizer/abstract_categorizer.rb', line 26 def handle_current(_offence) raise NotImplementedError, 'this method needs to be implemented in '\ 'subclasses' end |