Class: Bosh::Cli::TaskTracking::StageCollectionPresenter
- Defined in:
- lib/cli/task_tracking/stage_collection_presenter.rb
Constant Summary collapse
- JUSTIFY =
9
Instance Method Summary collapse
- #end_stage(stage, prefix_msg) ⇒ Object
- #end_task(task, prefix_msg, suffix_msg) ⇒ Object
- #fail_stage(stage) ⇒ Object
- #fail_task(task) ⇒ Object
- #finish_stage(stage) ⇒ Object
- #finish_task(task) ⇒ Object
-
#initialize(printer) ⇒ StageCollectionPresenter
constructor
A new instance of StageCollectionPresenter.
- #start_stage(stage) ⇒ Object
- #start_task(task) ⇒ Object
Constructor Details
#initialize(printer) ⇒ StageCollectionPresenter
Returns a new instance of StageCollectionPresenter.
5 6 7 8 9 |
# File 'lib/cli/task_tracking/stage_collection_presenter.rb', line 5 def initialize(printer) @printer = printer @last_stage = nil @last_task = nil end |
Instance Method Details
#end_stage(stage, prefix_msg) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cli/task_tracking/stage_collection_presenter.rb', line 33 def end_stage(stage, prefix_msg) duration = duration_str(stage) msg = "#{prefix_msg.rjust(JUSTIFY)} #{header_for_stage(stage)}#{duration}" if stage == @last_stage if stage.total == 1 # end_task added inline end message else @printer.print(:before, msg) end else @printer.print(:line_before, msg) end @last_stage = stage @last_task = nil end |
#end_task(task, prefix_msg, suffix_msg) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/cli/task_tracking/stage_collection_presenter.rb', line 77 def end_task(task, prefix_msg, suffix_msg) duration = duration_str(task) msg = "#{prefix_msg.rjust(JUSTIFY)} #{full_header_for_task(task)}#{suffix_msg}#{duration}" if task == @last_task @printer.print(:none, ". #{prefix_msg}#{suffix_msg}#{duration}") elsif task.stage.similar?(@last_stage) @printer.print(:before, msg) else @printer.print(:line_before, msg) end @last_stage = task.stage @last_task = task end |
#fail_stage(stage) ⇒ Object
29 30 31 |
# File 'lib/cli/task_tracking/stage_collection_presenter.rb', line 29 def fail_stage(stage) end_stage(stage, 'Failed') end |
#fail_task(task) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/cli/task_tracking/stage_collection_presenter.rb', line 70 def fail_task(task) error_msg = task.error error_msg = ": #{error_msg.make_red}" if error_msg end_task(task, 'Failed', error_msg) end |
#finish_stage(stage) ⇒ Object
25 26 27 |
# File 'lib/cli/task_tracking/stage_collection_presenter.rb', line 25 def finish_stage(stage) end_stage(stage, 'Done') end |
#finish_task(task) ⇒ Object
66 67 68 |
# File 'lib/cli/task_tracking/stage_collection_presenter.rb', line 66 def finish_task(task) end_task(task, 'Done', nil) end |
#start_stage(stage) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cli/task_tracking/stage_collection_presenter.rb', line 11 def start_stage(stage) msg_new_line = " Started #{header_for_stage(stage)}" # Assume that duplicate start events are never received if stage.similar?(@last_stage) @printer.print(:before, msg_new_line) else @printer.print(:line_before, msg_new_line) end @last_stage = stage @last_task = nil end |
#start_task(task) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cli/task_tracking/stage_collection_presenter.rb', line 51 def start_task(task) msg = " Started #{full_header_for_task(task)}" if task.stage == @last_stage && task.stage.total == 1 @printer.print(:none, " > #{task.name.make_green}") elsif task.stage.similar?(@last_stage) @printer.print(:before, msg) else @printer.print(:line_before, msg) end @last_stage = task.stage @last_task = task end |