Class: Ast::Merge::Detector::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/ast/merge/detector/base.rb

Overview

This class is abstract.

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.

Subclasses must implement:

  • #region_type - Returns the type symbol for detected regions
  • #detect_all - Finds all regions of this type in a document

Examples:

Implementing a custom detector

class MyBlockDetector < Ast::Merge::Detector::Base
  def region_type
    :my_block
  end

  def detect_all(source)
    # Return array of Region structs
    []
  end
end

Direct Known Subclasses

FencedCodeBlock, TomlFrontmatter, YamlFrontmatter

Instance Method Summary collapse

Instance Method Details

#detect_all(_source) ⇒ Array<Region>

This method is abstract.

Detects all regions of this type in the given source.

Parameters:

  • _source (String)

    The full document content to scan

Returns:

  • (Array<Region>)

    All detected regions, sorted by start_line

Raises:

  • (NotImplementedError)


150
151
152
# File 'lib/ast/merge/detector/base.rb', line 150

def detect_all(_source)
  raise NotImplementedError, "#{self.class}#detect_all must be implemented"
end

#inspectString

Returns:

  • (String)


167
168
169
# File 'lib/ast/merge/detector/base.rb', line 167

def inspect
  "#<#{name} region_type=#{region_type}>"
end

#nameString

A human-readable name for this detector.

Returns:

  • (String)


162
163
164
# File 'lib/ast/merge/detector/base.rb', line 162

def name
  self.class.name || "AnonymousDetector"
end

#region_typeSymbol

This method is abstract.

Returns the type symbol for regions detected by this detector.

Returns:

  • (Symbol)

Raises:

  • (NotImplementedError)


142
143
144
# File 'lib/ast/merge/detector/base.rb', line 142

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.

Returns:

  • (Boolean)


156
157
158
# File 'lib/ast/merge/detector/base.rb', line 156

def strip_delimiters?
  true
end