Preserve stage values and use StaticModel
This commit is contained in:
parent
d865aedafc
commit
2f972ad47b
|
@ -1,23 +1,29 @@
|
||||||
module Ci
|
module Ci
|
||||||
class Stage < ActiveRecord::Base
|
# Currently this is artificial object, constructed dynamically
|
||||||
include ActiveModel::Model
|
# We should migrate this object to actual database record in the future
|
||||||
|
class Stage
|
||||||
|
include StaticModel
|
||||||
|
|
||||||
attr_reader :pipeline, :name
|
attr_reader :pipeline, :name
|
||||||
|
|
||||||
def initialize(pipeline, name: name, status: status = nil)
|
def initialize(pipeline, name: name, status: nil)
|
||||||
@pipeline, @name, @status = pipeline, name, status
|
@pipeline, @name, @status = pipeline, name, status
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_param
|
||||||
|
name
|
||||||
|
end
|
||||||
|
|
||||||
def status
|
def status
|
||||||
@status ||= statuses.latest.status
|
@status ||= statuses.latest.status
|
||||||
end
|
end
|
||||||
|
|
||||||
def statuses
|
def statuses
|
||||||
pipeline.statuses.where(stage: stage)
|
@statuses ||= pipeline.statuses.where(stage: stage)
|
||||||
end
|
end
|
||||||
|
|
||||||
def builds
|
def builds
|
||||||
pipeline.builds.where(stage: stage)
|
@builds ||= pipeline.builds.where(stage: stage)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue