Class: Rubino::Compression::LineSkeleton

Inherits:
Object
  • Object
show all
Defined in:
lib/rubino/compression/line_skeleton.rb

Overview

Language-AGNOSTIC base for turning a whole source file into a SKELETON: signatures/comments/structure are kept VERBATIM and only LARGE bodies are elided, each replaced by a single pointer line that is itself a targeted read:

# … 14 lines elided — read app/loop.rb offset=120 limit=14

The pointer’s offset is the EXACT 1-based start line of the elided body in the ORIGINAL file and limit is the exact line count, so the model can issue ‘read app/loop.rb offset=120 limit=14` and get those original bytes back byte-for-byte (the drill-in invariant). Indentation of the elided body’s first line is preserved on the pointer so the skeleton still reads as code.

This base owns the GENERIC mechanics (the pointer format, the splice, the build template). A per-language subclass supplies ONLY ‘collect_elisions`, using its own parser to find the bodies worth eliding.

Defined Under Namespace

Classes: Elision

Instance Method Summary collapse

Constructor Details

#initialize(keep_method_body_max_lines:) ⇒ LineSkeleton

Returns a new instance of LineSkeleton.



28
29
30
# File 'lib/rubino/compression/line_skeleton.rb', line 28

def initialize(keep_method_body_max_lines:)
  @keep_max = keep_method_body_max_lines.to_i
end

Instance Method Details

#build(source, pointer_path:) ⇒ Object

Returns the skeleton String, or nil when the source can’t be skeletonised (the subclass’s parser failed) — the caller then falls back to the original. ‘pointer_path` is the display path embedded verbatim in each pointer line so the model can copy it straight into a `read` call.

Also yields, per elision, the exact original (first_line, line_count) so the caller can record elided ranges for drill-in detection.



39
40
41
42
43
44
45
46
# File 'lib/rubino/compression/line_skeleton.rb', line 39

def build(source, pointer_path:)
  elisions = collect_elisions(source)
  return nil if elisions.nil?         # parser failed → caller passes through
  return source if elisions.empty?    # parsed fine but nothing big enough to elide

  elisions.each { |e| yield e.first_line, e.line_count } if block_given?
  splice(source.lines, elisions, pointer_path)
end