Class: GemContribute::Output::Standard

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_contribute/output/standard.rb

Overview

Semantic output abstraction for CLI verbs (per ADR-0012). Wraps stdout/stderr behind verb-shaped methods so the look-and-feel can evolve independently of the service layer.

‘#warn` and `#error` both write to stderr without prefixing — the caller’s message already carries its own framing (“Note: …”, “warning: …”, “fix failed: …”). The semantic split exists so a later styling pass (color, severity icons) has somewhere to hang.

‘#progress` has two forms:

* No block — equivalent to #info. Use when there's nothing to
  wrap, e.g. you're announcing intent before a sequence of calls.
* Block form — runs the block while showing a tty-spinner in
  interactive terminals. In non-TTY contexts (CI, piped output,
  test StringIOs) it falls back to a plain line + yield. The
  block's return value is the method's return value.

Instance Method Summary collapse

Constructor Details

#initialize(out: $stdout, err: $stderr) ⇒ Standard

Returns a new instance of Standard.



25
26
27
28
# File 'lib/gem_contribute/output/standard.rb', line 25

def initialize(out: $stdout, err: $stderr)
  @out = out
  @err = err
end

Instance Method Details

#error(message) ⇒ Object



45
46
47
# File 'lib/gem_contribute/output/standard.rb', line 45

def error(message)
  @err.puts(message)
end

#info(message) ⇒ Object



30
31
32
# File 'lib/gem_contribute/output/standard.rb', line 30

def info(message)
  @out.puts(message)
end

#progress(message) ⇒ Object



34
35
36
37
38
39
# File 'lib/gem_contribute/output/standard.rb', line 34

def progress(message, &)
  return @out.puts(message) unless block_given?
  return puts_and_yield(message, &) unless interactive?

  spin(message, &)
end

#warn(message) ⇒ Object



41
42
43
# File 'lib/gem_contribute/output/standard.rb', line 41

def warn(message)
  @err.puts(message)
end