Class: Rigor::ModuleGraph::StatusReporter
- Inherits:
-
Object
- Object
- Rigor::ModuleGraph::StatusReporter
- Defined in:
- lib/rigor/module_graph/status_reporter.rb
Overview
Step-level progress reporter that prints to stderr.
On a TTY the message + elapsed time render inline on a single line (“==> Running rigor check… done (4.32s)”). When stderr is redirected (CI logs, piping into another command, ‘tee` to a file) both halves print on separate lines so the output stays line-oriented and grep-friendly.
‘quiet: true` silences every method; callers can wire a `–quiet` CLI flag through without litterring conditionals at each call site.
Usage:
status = StatusReporter.new(stderr: $stderr)
edges = status.step("Running rigor check") do
runner.edges_for(paths)
end
status.info "#{edges.size} edges"
Instance Method Summary collapse
-
#info(message) ⇒ Object
Print an informational line indented under the most recent step.
-
#initialize(stderr:, quiet: false) ⇒ StatusReporter
constructor
A new instance of StatusReporter.
-
#step(message) ⇒ Object
Print a “==> message…” line, yield, then print the outcome (“done (Xms)” or “failed”) with elapsed time.
Constructor Details
#initialize(stderr:, quiet: false) ⇒ StatusReporter
Returns a new instance of StatusReporter.
25 26 27 28 29 |
# File 'lib/rigor/module_graph/status_reporter.rb', line 25 def initialize(stderr:, quiet: false) @stderr = stderr @quiet = quiet @tty = stderr.respond_to?(:tty?) && stderr.tty? end |
Instance Method Details
#info(message) ⇒ Object
Print an informational line indented under the most recent step. Used for “2016 edges, 87 nodes” style post-step counts.
54 55 56 57 58 |
# File 'lib/rigor/module_graph/status_reporter.rb', line 54 def info() return if @quiet @stderr.puts " #{}" end |
#step(message) ⇒ Object
Print a “==> message…” line, yield, then print the outcome (“done (Xms)” or “failed”) with elapsed time. Returns whatever the block returns; re-raises on exception after printing the failure tail so callers can still rescue normally.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rigor/module_graph/status_reporter.rb', line 36 def step() return yield if @quiet start_step() started_at = monotonic begin result = yield rescue StandardError finish_step("failed", monotonic - started_at) raise end finish_step("done", monotonic - started_at) result end |