2014-07-29 14:10:15 +00:00
|
|
|
class Label < ActiveRecord::Base
|
|
|
|
belongs_to :project
|
|
|
|
has_many :label_links, dependent: :destroy
|
2014-07-30 12:15:39 +00:00
|
|
|
has_many :issues, through: :label_links, source: :target, source_type: 'Issue'
|
2014-07-29 14:10:15 +00:00
|
|
|
|
2014-08-11 21:59:30 +00:00
|
|
|
validates :color,
|
|
|
|
format: { with: /\A\#[0-9A-Fa-f]{6}+\Z/ },
|
|
|
|
allow_blank: false
|
2014-07-29 14:10:15 +00:00
|
|
|
validates :project, presence: true
|
2014-07-30 10:26:54 +00:00
|
|
|
|
2014-08-11 21:59:30 +00:00
|
|
|
# Don't allow '?', '&', and ',' for label titles
|
2014-08-12 08:53:50 +00:00
|
|
|
validates :title,
|
|
|
|
presence: true,
|
|
|
|
format: { with: /\A[^&\?,&]*\z/ },
|
|
|
|
uniqueness: true
|
2014-07-29 16:19:26 +00:00
|
|
|
|
2014-07-30 16:13:35 +00:00
|
|
|
scope :order_by_name, -> { reorder("labels.title ASC") }
|
|
|
|
|
2014-07-29 16:19:26 +00:00
|
|
|
def name
|
|
|
|
title
|
|
|
|
end
|
2014-07-30 12:15:39 +00:00
|
|
|
|
|
|
|
def open_issues_count
|
|
|
|
issues.opened.count
|
|
|
|
end
|
2014-07-29 14:10:15 +00:00
|
|
|
end
|