# -*- encoding : utf-8 -*- class BuildList::Item < ActiveRecord::Base belongs_to :build_list, :touch => true attr_protected :build_list_id GIT_ERROR = 5 STATUSES = [BuildList::SUCCESS, BuildList::DEPENDENCIES_ERROR, BuildList::BUILD_ERROR, BuildList::BUILD_STARTED, GIT_ERROR, BuildList::BUILD_CANCELED] HUMAN_STATUSES = { nil => :unknown, GIT_ERROR => :git_error, BuildList::DEPENDENCIES_ERROR => :dependencies_error, BuildList::SUCCESS => :success, BuildList::BUILD_STARTED => :build_started, BuildList::BUILD_ERROR => :build_error, BuildList::BUILD_CANCELED => :build_canceled } scope :recent, order("#{table_name}.level ASC, #{table_name}.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 end