Class: DaggerRuby::Progress
- Inherits:
-
Object
- Object
- DaggerRuby::Progress
- Defined in:
- lib/dagger_ruby/progress.rb
Defined Under Namespace
Classes: Relay
Constant Summary collapse
- SOCKET_ENV =
"DAGGER_RUBY_PROGRESS_SOCKET"
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(out: $stdout, enabled: true, streaming: false, color: false, relay: nil) ⇒ Progress
constructor
A new instance of Progress.
- #message(text) ⇒ Object
- #render(event) ⇒ Object
- #step(name) ⇒ Object
- #streaming? ⇒ Boolean
- #write(output = nil) ⇒ Object
Constructor Details
#initialize(out: $stdout, enabled: true, streaming: false, color: false, relay: nil) ⇒ Progress
Returns a new instance of Progress.
35 36 37 38 39 40 41 42 |
# File 'lib/dagger_ruby/progress.rb', line 35 def initialize(out: $stdout, enabled: true, streaming: false, color: false, relay: nil) @out = out @enabled = enabled @streaming = streaming @color = color @relay = relay @step = 0 end |
Class Method Details
.silent ⇒ Object
31 32 33 |
# File 'lib/dagger_ruby/progress.rb', line 31 def self.silent @silent ||= new(enabled: false) end |
Instance Method Details
#close ⇒ Object
80 81 82 |
# File 'lib/dagger_ruby/progress.rb', line 80 def close @relay&.close end |
#message(text) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/dagger_ruby/progress.rb', line 72 def (text) return unless @enabled return @relay.emit(type: "message", text: text.to_s) if @relay @out.puts text @out.flush end |
#render(event) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/dagger_ruby/progress.rb', line 84 def render(event) case event.fetch("type") when "message" @out.puts event.fetch("text") when "start" @out.puts step_heading(event.fetch("step"), event.fetch("name")) when "finish" status = event.fetch("status") @out.puts step_result(event.fetch("step"), status, event.fetch("elapsed"), color: status_color(status)) end @out.flush end |
#step(name) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/dagger_ruby/progress.rb', line 46 def step(name) return yield unless @enabled number = next_step started_at = monotonic_time start_step(number, name) result = yield finish_step(number, "DONE", elapsed_since(started_at)) result rescue Interrupt finish_step(number, "CANCELED", elapsed_since(started_at)) if number raise rescue StandardError finish_step(number, "ERROR", elapsed_since(started_at)) if number raise end |
#streaming? ⇒ Boolean
44 |
# File 'lib/dagger_ruby/progress.rb', line 44 def streaming? = @streaming |
#write(output = nil) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/dagger_ruby/progress.rb', line 63 def write(output = nil) return unless @enabled output = yield if block_given? text = output.to_s text.each_line { |line| @out.print " #{line}" } @out.puts unless text.empty? || text.end_with?("\n") end |