2016-07-27 15:32:32 -04:00
|
|
|
class List < ActiveRecord::Base
|
|
|
|
belongs_to :board
|
|
|
|
belongs_to :label
|
|
|
|
|
2016-07-28 18:26:16 -04:00
|
|
|
enum list_type: { backlog: 0, label: 1, done: 2 }
|
2016-07-27 15:32:32 -04:00
|
|
|
|
2016-07-28 18:26:16 -04:00
|
|
|
validates :board, :list_type, presence: true
|
|
|
|
validates :label, :position, presence: true, if: :label?
|
|
|
|
validates :position, numericality: { only_integer: true, greater_than_or_equal_to: 0 }, if: :label?
|
2016-07-31 19:45:56 -04:00
|
|
|
|
|
|
|
delegate :name, to: :label, allow_nil: true, prefix: true
|
|
|
|
|
2016-07-31 19:48:00 -04:00
|
|
|
before_destroy :can_be_destroyed, unless: :label?
|
|
|
|
|
2016-07-31 19:45:56 -04:00
|
|
|
def title
|
|
|
|
label? ? label_name : list_type.humanize
|
|
|
|
end
|
2016-07-31 19:48:00 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def can_be_destroyed
|
|
|
|
false
|
|
|
|
end
|
2016-07-27 15:32:32 -04:00
|
|
|
end
|