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.
Class Method Summary collapse
-
.command(cmd, type: :info, output: $stdout) ⇒ Object
Stream from a subprocess command.
-
.error(source, output: $stdout) {|line| ... } ⇒ void
Stream lines with an error symbol (red).
-
.info(source, output: $stdout) {|line| ... } ⇒ void
Stream lines with an info symbol (cyan).
-
.message(source, output: $stdout) ⇒ void
Stream lines with a plain bar prefix (no symbol).
-
.step(source, output: $stdout) {|line| ... } ⇒ void
Stream lines with a step symbol (green).
-
.success(source, output: $stdout) {|line| ... } ⇒ void
Stream lines with a success symbol (green).
-
.warn(source, output: $stdout) {|line| ... } ⇒ void
Stream lines with a warning symbol (yellow).
Class Method Details
.command(cmd, type: :info, output: $stdout) ⇒ Object
Stream from a subprocess command. Usage: Clack.stream.command(“npm install”, type: :info) Returns true on success, false on failure or if command cannot be executed
70 71 72 73 74 75 76 77 |
# File 'lib/clack/stream.rb', line 70 def command(cmd, type: :info, output: $stdout) IO.popen(cmd, err: %i[child out]) do |io| send(type, io, output: output) end $CHILD_STATUS.success? rescue Errno::ENOENT false end |
.error(source, output: $stdout) {|line| ... } ⇒ void
This method returns an undefined value.
Stream lines with an error symbol (red).
52 53 54 |
# File 'lib/clack/stream.rb', line 52 def error(source, output: $stdout, &block) stream_with_symbol(source, Symbols::S_ERROR, :red, output, &block) end |
.info(source, output: $stdout) {|line| ... } ⇒ void
This method returns an undefined value.
Stream lines with an info symbol (cyan).
16 17 18 |
# File 'lib/clack/stream.rb', line 16 def info(source, output: $stdout, &block) stream_with_symbol(source, Symbols::S_INFO, :cyan, output, &block) end |
.message(source, output: $stdout) ⇒ void
This method returns an undefined value.
Stream lines with a plain bar prefix (no symbol).
60 61 62 63 64 65 |
# File 'lib/clack/stream.rb', line 60 def (source, output: $stdout) each_line(source) do |line| output.puts "#{Colors.gray(Symbols::S_BAR)} #{line.chomp}" output.flush end end |
.step(source, output: $stdout) {|line| ... } ⇒ void
This method returns an undefined value.
Stream lines with a step symbol (green).
34 35 36 |
# File 'lib/clack/stream.rb', line 34 def step(source, output: $stdout, &block) stream_with_symbol(source, Symbols::S_STEP_SUBMIT, :green, output, &block) end |
.success(source, output: $stdout) {|line| ... } ⇒ void
This method returns an undefined value.
Stream lines with a success symbol (green).
25 26 27 |
# File 'lib/clack/stream.rb', line 25 def success(source, output: $stdout, &block) stream_with_symbol(source, Symbols::S_SUCCESS, :green, output, &block) end |