Class: Rigor::SigGen::WriteResult

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

Overview

Per-source-file outcome of a rigor sig-gen --write run.

The writer reports back what it did so the renderer (and the CLI's exit-status logic) can summarise actions and surface user-authored-skip decisions without having to re-parse the produced files.

  • source_path — original .rb file.
  • target_path.rbs file the writer was responsible for (nil when the source path falls outside the project signature tree, in which case action is :skipped_outside_sig_root).
  • action — one of :created / :updated / :noop / :skipped_outside_sig_root / :skipped_invalid_rbs / :skipped_invalid_encoding.
  • applied — the MethodCandidates that actually landed on disk.
  • skipped — the MethodCandidates the writer declined (e.g. tighter-return without --overwrite). Each entry pairs the candidate with a skip reason keyword (:user_authored).
  • error — the refusal cause, when action is a refusal: for :skipped_invalid_rbs the file the writer assembled does not parse, so it was NOT written (writing it would poison the project's sig tree — the consumer quarantines an unparseable .rbs, taking every other type in that file down with it); for :skipped_invalid_encoding the EXISTING target file is not valid UTF-8, so the writer refuses to merge into content it cannot read faithfully.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_path:, target_path:, action:, applied: [], skipped: [], error: nil) ⇒ WriteResult

Returns a new instance of WriteResult.



26
27
28
29
30
31
32
33
34
# File 'lib/rigor/sig_gen/write_result.rb', line 26

def initialize(source_path:, target_path:, action:, applied: [], skipped: [], error: nil)
  @source_path = source_path
  @target_path = target_path
  @action = action
  @applied = applied.freeze
  @skipped = skipped.freeze
  @error = error
  freeze
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



24
25
26
# File 'lib/rigor/sig_gen/write_result.rb', line 24

def action
  @action
end

#appliedObject (readonly)

Returns the value of attribute applied.



24
25
26
# File 'lib/rigor/sig_gen/write_result.rb', line 24

def applied
  @applied
end

#errorObject (readonly)

Returns the value of attribute error.



24
25
26
# File 'lib/rigor/sig_gen/write_result.rb', line 24

def error
  @error
end

#skippedObject (readonly)

Returns the value of attribute skipped.



24
25
26
# File 'lib/rigor/sig_gen/write_result.rb', line 24

def skipped
  @skipped
end

#source_pathObject (readonly)

Returns the value of attribute source_path.



24
25
26
# File 'lib/rigor/sig_gen/write_result.rb', line 24

def source_path
  @source_path
end

#target_pathObject (readonly)

Returns the value of attribute target_path.



24
25
26
# File 'lib/rigor/sig_gen/write_result.rb', line 24

def target_path
  @target_path
end

Instance Method Details

#to_hObject



36
37
38
39
40
41
42
43
44
# File 'lib/rigor/sig_gen/write_result.rb', line 36

def to_h
  {
    source: source_path,
    target: target_path&.to_s,
    action: action.to_s,
    applied: applied.map(&:to_h),
    skipped: skipped.map { |c, reason| c.to_h.merge(write_skip_reason: reason.to_s) }
  }.tap { |h| h[:error] = error if error }
end