rosa-build/app/models/build_list/item.rb

39 lines
954 B
Ruby
Raw Normal View History

2011-04-11 11:47:57 +01:00
class BuildList::Item < ActiveRecord::Base
belongs_to :build_list
attr_protected :build_list_id
2011-10-29 18:50:47 +01:00
STATUSES = [BuildServer::SUCCESS, BuildServer::DEPENDENCIES_FAIL, BuildServer::BUILD_ERROR]
2011-04-11 11:47:57 +01:00
HUMAN_STATUSES = {
2011-04-22 17:13:47 +01:00
nil => :unknown,
2011-04-11 11:47:57 +01:00
BuildServer::DEPENDENCIES_FAIL => :dependencies_fail,
2011-10-29 18:50:47 +01:00
BuildServer::SUCCESS => :success,
BuildServer::BUILD_ERROR => :build_error
2011-04-11 11:47:57 +01:00
}
scope :recent, order("level ASC, name ASC")
def self.group_by_level
items = scoped({}).recent
groups = []
current_level = -1
items.each do |item|
groups << [] if current_level < item.level
groups.last << item
current_level = item.level
end
groups
end
def self.human_status(status)
I18n.t("layout.build_lists.items.statuses.#{HUMAN_STATUSES[status]}")
end
def human_status
self.class.human_status(status)
end
2011-04-22 17:13:47 +01:00
end