gitlab-org--gitlab-foss/app/models/global_label.rb

33 lines
669 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class GlobalLabel
include Presentable
attr_accessor :title, :labels
alias_attribute :name, :title
delegate :color, :text_color, :description, :scoped_label?, to: :@first_label
2016-03-06 23:07:19 -05:00
def for_display
@first_label
end
def self.build_collection(labels)
labels = labels.group_by(&:title)
2016-03-06 23:07:19 -05:00
labels.map do |title, labels|
new(title, labels)
end
end
def initialize(title, labels)
@title = title
@labels = labels
2016-03-06 23:07:19 -05:00
@first_label = labels.find { |lbl| lbl.description.present? } || labels.first
end
def present(attributes)
super(attributes.merge(presenter_class: ::LabelPresenter))
end
end