Class: Tng::UI::ProgressUpdater
- Inherits:
-
Object
- Object
- Tng::UI::ProgressUpdater
- Defined in:
- lib/tng/ui/go_ui_session.rb
Overview
Helper class for updating progress bar from within a block
Instance Method Summary collapse
-
#error(message) ⇒ Object
Report an error.
-
#initialize(control_file) ⇒ ProgressUpdater
constructor
A new instance of ProgressUpdater.
-
#update(message, percent = nil, step_increment: true, explicit_step: nil) ⇒ Object
Update progress with a new step.
Constructor Details
#initialize(control_file) ⇒ ProgressUpdater
Returns a new instance of ProgressUpdater.
553 554 555 556 |
# File 'lib/tng/ui/go_ui_session.rb', line 553 def initialize(control_file) @control_file = control_file @step = 0 end |
Instance Method Details
#error(message) ⇒ Object
Report an error
582 583 584 585 586 |
# File 'lib/tng/ui/go_ui_session.rb', line 582 def error() data = { type: "error", message: } File.write(@control_file, JSON.generate(data)) sleep(0.1) end |
#update(message, percent = nil, step_increment: true, explicit_step: nil) ⇒ Object
Update progress with a new step
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 |
# File 'lib/tng/ui/go_ui_session.rb', line 563 def update(, percent = nil, step_increment: true, explicit_step: nil) step_idx = if explicit_step explicit_step elsif step_increment @step else (@step > 0 ? @step - 1 : 0) end data = { type: "step", step: step_idx, message: } data[:percent] = percent if percent File.write(@control_file, JSON.generate(data)) @step += 1 if step_increment && explicit_step.nil? sleep(0.1) # Give UI time to update end |