label.rb 627 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

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

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

Robert Schilling's avatar
Robert Schilling committed
17
  alias_attribute :name, :title
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
18
19
20
21

  def open_issues_count
    issues.opened.count
  end
22
end