Class: Tng::UI::JsonProgressReporter
- Inherits:
-
Object
- Object
- Tng::UI::JsonProgressReporter
- Defined in:
- lib/tng/ui/json_session.rb
Instance Method Summary collapse
- #error(message) ⇒ Object
-
#initialize ⇒ JsonProgressReporter
constructor
A new instance of JsonProgressReporter.
- #update(message, percent = nil, step_increment: true, explicit_step: nil) ⇒ Object
Constructor Details
#initialize ⇒ JsonProgressReporter
Returns a new instance of JsonProgressReporter.
203 204 205 |
# File 'lib/tng/ui/json_session.rb', line 203 def initialize @step = 0 end |
Instance Method Details
#error(message) ⇒ Object
219 220 221 |
# File 'lib/tng/ui/json_session.rb', line 219 def error() puts JSON.generate({ type: "error", message: }) end |
#update(message, percent = nil, step_increment: true, explicit_step: nil) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/tng/ui/json_session.rb', line 207 def update(, percent = nil, step_increment: true, explicit_step: nil) step_idx = explicit_step || @step payload = { type: "progress_update", message: } payload[:percent] = percent if percent payload[:step] = step_idx puts JSON.generate(payload) @step += 1 if step_increment && explicit_step.nil? end |