Module: Clack::Stream
- Defined in:
- lib/clack/stream.rb
Overview
Stream logging utility for iterables, enumerables, and IO streams. Similar to Log but works with streaming data in real-time.
Every method accepts with_guide: (default: the global setting). With
guides off the level symbol stays on the first line and continuation
lines lose their rail prefix.
Class Method Summary collapse
-
.command(cmd, type: :info, with_guide: nil, output: $stdout) ⇒ Boolean
Stream from a subprocess command.
-
.error(source, with_guide: nil, output: $stdout) {|line| ... } ⇒ void
Stream lines with an error symbol (red).
-
.info(source, with_guide: nil, output: $stdout) {|line| ... } ⇒ void
Stream lines with an info symbol (cyan).
-
.message(source, with_guide: nil, output: $stdout) ⇒ void
Stream lines with a plain bar prefix (no symbol), or bare lines with guides off.
-
.step(source, with_guide: nil, output: $stdout) {|line| ... } ⇒ void
Stream lines with a step symbol (green).
-
.success(source, with_guide: nil, output: $stdout) {|line| ... } ⇒ void
Stream lines with a success symbol (green).
-
.warn(source, with_guide: nil, output: $stdout) {|line| ... } ⇒ void
Stream lines with a warning symbol (yellow).
Class Method Details
.command(cmd, type: :info, with_guide: nil, output: $stdout) ⇒ Boolean
Stream from a subprocess command. Usage: Clack.stream.command("npm install", type: :info)
85 86 87 88 89 90 91 92 |
# File 'lib/clack/stream.rb', line 85 def command(cmd, type: :info, with_guide: nil, output: $stdout) IO.popen(cmd, err: %i[child out]) do |io| send(type, io, with_guide:, output:) end $CHILD_STATUS.success? rescue Errno::ENOENT false end |
.error(source, with_guide: nil, output: $stdout) {|line| ... } ⇒ void
This method returns an undefined value.
Stream lines with an error symbol (red).
61 62 63 |
# File 'lib/clack/stream.rb', line 61 def error(source, with_guide: nil, output: $stdout, &block) stream_with_symbol(source, Symbols::S_ERROR, :red, with_guide, output, &block) end |
.info(source, with_guide: nil, output: $stdout) {|line| ... } ⇒ void
This method returns an undefined value.
Stream lines with an info symbol (cyan).
21 22 23 |
# File 'lib/clack/stream.rb', line 21 def info(source, with_guide: nil, output: $stdout, &block) stream_with_symbol(source, Symbols::S_INFO, :cyan, with_guide, output, &block) end |
.message(source, with_guide: nil, output: $stdout) ⇒ void
This method returns an undefined value.
Stream lines with a plain bar prefix (no symbol), or bare lines with guides off.
70 71 72 73 74 75 76 |
# File 'lib/clack/stream.rb', line 70 def (source, with_guide: nil, output: $stdout) prefix = rail_prefix(with_guide) each_line(source) do |line| output.puts "#{prefix}#{line.chomp}" output.flush end end |
.step(source, with_guide: nil, output: $stdout) {|line| ... } ⇒ void
This method returns an undefined value.
Stream lines with a step symbol (green).
41 42 43 |
# File 'lib/clack/stream.rb', line 41 def step(source, with_guide: nil, output: $stdout, &block) stream_with_symbol(source, Symbols::S_STEP_SUBMIT, :green, with_guide, output, &block) end |
.success(source, with_guide: nil, output: $stdout) {|line| ... } ⇒ void
This method returns an undefined value.
Stream lines with a success symbol (green).
31 32 33 |
# File 'lib/clack/stream.rb', line 31 def success(source, with_guide: nil, output: $stdout, &block) stream_with_symbol(source, Symbols::S_SUCCESS, :green, with_guide, output, &block) end |
.warn(source, with_guide: nil, output: $stdout) {|line| ... } ⇒ void
This method returns an undefined value.
Stream lines with a warning symbol (yellow).
51 52 53 |
# File 'lib/clack/stream.rb', line 51 def warn(source, with_guide: nil, output: $stdout, &block) stream_with_symbol(source, Symbols::S_WARN, :yellow, with_guide, output, &block) end |