BigW Consortium Gitlab

global_label.rb 448 Bytes
Newer Older
1 2 3 4
class GlobalLabel
  attr_accessor :title, :labels
  alias_attribute :name, :title

5 6
  delegate :color, :description, to: :@first_label

7 8 9
  def self.build_collection(labels)
    labels = labels.group_by(&:title)

10 11
    labels.map do |title, labels|
      new(title, labels)
12 13 14 15 16 17
    end
  end

  def initialize(title, labels)
    @title = title
    @labels = labels
18
    @first_label = labels.find { |lbl| lbl.description.present? } || labels.first
19 20
  end
end