label.rb 508 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
  validates :color, format: { with: /\A\#[0-9A-Fa-f]{6}+\Z/ }, allow_blank: true
7
  validates :project, presence: true
8
9
10

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

  def name
    title
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
15
16
17
18

  def open_issues_count
    issues.opened.count
  end
19
end