Class: Ast::Merge::RegionDetectorBase Abstract
- Inherits:
-
Object
- Object
- Ast::Merge::RegionDetectorBase
- Defined in:
- lib/ast/merge/region_detector_base.rb
Overview
Subclass and implement #region_type and #detect_all
Base class for region detection.
Region detectors identify portions of a document that should be handled by a specialized merger. For example, detecting YAML frontmatter in a Markdown file, or Ruby code blocks that should be merged with Prism.
Subclasses must implement:
-
#region_type - Returns the type symbol for detected regions
-
#detect_all - Finds all regions of this type in a document
Direct Known Subclasses
FencedCodeBlockDetector, TomlFrontmatterDetector, YamlFrontmatterDetector
Instance Method Summary collapse
-
#detect_all(source) ⇒ Array<Region>
abstract
Detects all regions of this type in the given source.
-
#inspect ⇒ String
Returns a string representation of this detector.
-
#name ⇒ String
A human-readable name for this detector.
-
#region_type ⇒ Symbol
abstract
Returns the type symbol for regions detected by this detector.
-
#strip_delimiters? ⇒ Boolean
Whether to strip delimiters from content before passing to merger.
Instance Method Details
#detect_all(source) ⇒ Array<Region>
Subclasses must implement this method
Detects all regions of this type in the given source.
58 59 60 |
# File 'lib/ast/merge/region_detector_base.rb', line 58 def detect_all(source) raise NotImplementedError, "#{self.class}#detect_all must be implemented" end |
#inspect ⇒ String
Returns a string representation of this detector.
87 88 89 |
# File 'lib/ast/merge/region_detector_base.rb', line 87 def inspect "#<#{name} region_type=#{region_type}>" end |
#name ⇒ String
A human-readable name for this detector.
Used in error messages and debugging output.
80 81 82 |
# File 'lib/ast/merge/region_detector_base.rb', line 80 def name self.class.name || "AnonymousDetector" end |
#region_type ⇒ Symbol
Subclasses must implement this method
Returns the type symbol for regions detected by this detector.
This symbol is used to identify the region type in the Region struct and for matching regions between template and destination documents.
37 38 39 |
# File 'lib/ast/merge/region_detector_base.rb', line 37 def region_type raise NotImplementedError, "#{self.class}#region_type must be implemented" end |
#strip_delimiters? ⇒ Boolean
Whether to strip delimiters from content before passing to merger.
When true (default), only the inner content is passed to the region’s merger. The delimiters are stored separately and reattached after merging.
When false, the full content including delimiters is passed to the merger, which must then handle the delimiters itself.
71 72 73 |
# File 'lib/ast/merge/region_detector_base.rb', line 71 def strip_delimiters? true end |