gitlab-org--gitlab-foss/app/models/global_label.rb
Jan Provaznik fec2e27f1d [backend] backport of scoped labels
Scoped labels in EE require additional changes in CE code.
2019-04-04 08:07:58 +02:00

26 lines
550 B
Ruby

# 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