label.rb 594 Bytes
Newer Older
1
2
3
class Label < ActiveRecord::Base
  belongs_to :project
  has_many :label_links, dependent: :destroy
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
4
  has_many :issues, through: :label_links, source: :target, source_type: 'Issue'
5

6
7
8
  validates :color,
            format: { with: /\A\#[0-9A-Fa-f]{6}+\Z/ },
            allow_blank: false
9
  validates :project, presence: true
10

11
  # Don't allow '?', '&', and ',' for label titles
12
  validates :title, presence: true, format: { with: /\A[^&\?,&]*\z/ }
13

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
14
15
  scope :order_by_name, -> { reorder("labels.title ASC") }

16
17
18
  def name
    title
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
19
20
21
22

  def open_issues_count
    issues.opened.count
  end
23
end