Class: Bosh::Cli::TaskTracking::Stage
- Defined in:
- lib/cli/task_tracking/stage_collection.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #duration ⇒ Object
-
#initialize(name, tags, total, callbacks) ⇒ Stage
constructor
A new instance of Stage.
- #similar?(other) ⇒ Boolean
- #update_with_event(event) ⇒ Object
Constructor Details
#initialize(name, tags, total, callbacks) ⇒ Stage
Returns a new instance of Stage.
24 25 26 27 28 29 30 |
# File 'lib/cli/task_tracking/stage_collection.rb', line 24 def initialize(name, , total, callbacks) @name = name @tags = Array() @total = total @callbacks = callbacks @tasks = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/cli/task_tracking/stage_collection.rb', line 22 def name @name end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
22 23 24 |
# File 'lib/cli/task_tracking/stage_collection.rb', line 22 def @tags end |
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
22 23 24 |
# File 'lib/cli/task_tracking/stage_collection.rb', line 22 def tasks @tasks end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
22 23 24 |
# File 'lib/cli/task_tracking/stage_collection.rb', line 22 def total @total end |
Instance Method Details
#==(other) ⇒ Object
63 64 65 66 |
# File 'lib/cli/task_tracking/stage_collection.rb', line 63 def ==(other) return false unless other.is_a?(Stage) [name, , total] == [other.name, other., other.total] end |
#duration ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cli/task_tracking/stage_collection.rb', line 45 def duration total_duration = TotalDuration.new task_start_times = @tasks.map(&:started_at) task_end_times = @tasks.map(&:finished_at) # If any task start time is nil, the start time for the entire stage is unknown. total_duration.started_at = task_start_times.min unless task_start_times.include?(nil) total_duration.finished_at = task_end_times.max unless task_end_times.include?(nil) total_duration.duration end |
#similar?(other) ⇒ Boolean
58 59 60 61 |
# File 'lib/cli/task_tracking/stage_collection.rb', line 58 def similar?(other) return false unless other.is_a?(Stage) name == other.name end |
#update_with_event(event) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cli/task_tracking/stage_collection.rb', line 32 def update_with_event(event) new_task = Task.new(self, event['task'], event['index'], event['progress'], @callbacks) unless found_task = @tasks.find { |s| s == new_task } found_task = new_task @tasks << new_task end fire_started_callback if started? found_task.update_with_event(event) fire_finished_callback if finished?(event) fire_failed_callback if failed?(event) found_task end |