Class: Rigor::SigGen::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/rigor/sig_gen/renderer.rb

Overview

Output formatter for ‘rigor sig-gen`.

Supports three modes:

  • ‘:print` (default) — RBS skeletons grouped by source file and class declaration, ready for the user to paste into `sig/<path>.rbs`.

  • ‘:diff` — a unified-style diff comparing the existing RBS spelling (if any) against the inferred spelling. The MVP renders a minimal “- declared / + inferred” block; full per-file diffing arrives with slice 2’s ‘–write` merge.

  • ‘:json` — machine-readable payload with the same classification table as `:print`.

Instance Method Summary collapse

Constructor Details

#initialize(out:) ⇒ Renderer

Returns a new instance of Renderer.



23
24
25
# File 'lib/rigor/sig_gen/renderer.rb', line 23

def initialize(out:)
  @out = out
end

Instance Method Details

#render(candidates:, mode:, format:, selection:) ⇒ Object

Parameters:

  • candidates (Array<MethodCandidate>)
  • mode (:print, :diff)
  • format (String)

    “text” or “json”

  • selection (Array<Symbol>)

    subset of Classification constants to include; an empty array means “all emittable classifications”.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rigor/sig_gen/renderer.rb', line 33

def render(candidates:, mode:, format:, selection:)
  filtered = filter(candidates, selection)

  case format
  when "json" then render_json(filtered)
  when "text"
    mode == :diff ? render_diff(filtered) : render_print(filtered)
  else
    raise ArgumentError, "unsupported format: #{format}"
  end
end

#render_write(results:, format:) ⇒ Object

Renders the per-source-file outcomes of a ‘–write` run. Distinct from #render because the write path’s reporting surface is action-oriented (created / updated / skipped) rather than candidate-oriented.



114
115
116
117
118
119
120
# File 'lib/rigor/sig_gen/renderer.rb', line 114

def render_write(results:, format:)
  case format
  when "json" then render_write_json(results)
  when "text" then render_write_text(results)
  else raise ArgumentError, "unsupported format: #{format}"
  end
end