Class: CruiseFace::Model::Stage::History

Inherits:
Object
  • Object
show all
Defined in:
lib/cruise_face/stage.rb

Overview

History of a Stage cares about completed jobs, which maybe inside a running Stage

Instance Method Summary collapse

Constructor Details

#initialize(stages) ⇒ History

Returns a new instance of History.



9
10
11
# File 'lib/cruise_face/stage.rb', line 9

def initialize(stages)
  @stages = stages
end

Instance Method Details

#as_jobsObject

A History of Stage could transform to a group of jobs, which is containing latest completed status in a Job’s history. In some cases, the job may not have completed status, then the running/canceled job would be included in the return jobs



46
47
48
# File 'lib/cruise_face/stage.rb', line 46

def as_jobs
  @jobs ||= find_latest_completed_jobs
end

#failed?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/cruise_face/stage.rb', line 20

def failed?
  !passed?
end

#failed_jobs_from_now_until_passed(job_name) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cruise_face/stage.rb', line 28

def failed_jobs_from_now_until_passed(job_name)
  jobs = []
  @stages.each do |stage|
    if job = stage.jobs.select(&:completed?).detect {|job| job.name == job_name}
      if job.failed?
        jobs << job
      else
        break
      end
    end
  end
  jobs
end

#firstObject



13
14
15
# File 'lib/cruise_face/stage.rb', line 13

def first
  @stages.first
end

#passed?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/cruise_face/stage.rb', line 17

def passed?
  as_jobs.all?(&:passed?)
end

#statusObject



24
25
26
# File 'lib/cruise_face/stage.rb', line 24

def status
  passed? ? 'Passed' : 'Failed'
end