2016-07-27 19:32:32 +00:00
|
|
|
class List < ActiveRecord::Base
|
|
|
|
belongs_to :board
|
|
|
|
belongs_to :label
|
|
|
|
|
2016-07-28 22:26:16 +00:00
|
|
|
enum list_type: { backlog: 0, label: 1, done: 2 }
|
2016-07-27 19:32:32 +00:00
|
|
|
|
2016-07-28 22:26:16 +00:00
|
|
|
validates :board, :list_type, presence: true
|
|
|
|
validates :label, :position, presence: true, if: :label?
|
2016-08-03 17:21:22 +00:00
|
|
|
validates :label_id, uniqueness: { scope: :board_id }, if: :label?
|
2016-07-28 22:26:16 +00:00
|
|
|
validates :position, numericality: { only_integer: true, greater_than_or_equal_to: 0 }, if: :label?
|
2016-07-31 23:45:56 +00:00
|
|
|
|
2016-07-31 23:48:00 +00:00
|
|
|
before_destroy :can_be_destroyed, unless: :label?
|
|
|
|
|
2016-07-31 23:45:56 +00:00
|
|
|
def title
|
2016-08-16 02:07:59 +00:00
|
|
|
label? ? label.name : list_type.humanize
|
2016-07-31 23:45:56 +00:00
|
|
|
end
|
2016-07-31 23:48:00 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def can_be_destroyed
|
|
|
|
false
|
|
|
|
end
|
2016-07-27 19:32:32 +00:00
|
|
|
end
|