Welcome to mirror list, hosted at ThFree Co, Russian Federation.

global_label.rb « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 572cb12b26ab2f3324115faabefa9bb1fe0a67e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

class GlobalLabel
  attr_accessor :title, :labels
  alias_attribute :name, :title

  delegate :color, :text_color, :description, :scoped_label?, to: :@first_label

  def for_display
    @first_label
  end

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

    labels.map do |title, labels|
      new(title, labels)
    end
  end

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