2020-04-23 17:09:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Sprint < ApplicationRecord
|
2020-04-30 20:09:59 -04:00
|
|
|
include Timebox
|
|
|
|
|
2020-04-27 05:09:51 -04:00
|
|
|
STATE_ID_MAP = {
|
|
|
|
active: 1,
|
|
|
|
closed: 2
|
|
|
|
}.with_indifferent_access.freeze
|
|
|
|
|
|
|
|
include AtomicInternalId
|
|
|
|
|
|
|
|
has_many :issues
|
|
|
|
has_many :merge_requests
|
|
|
|
|
2020-04-23 17:09:31 -04:00
|
|
|
belongs_to :project
|
|
|
|
belongs_to :group
|
2020-04-27 05:09:51 -04:00
|
|
|
|
|
|
|
has_internal_id :iid, scope: :project, init: ->(s) { s&.project&.sprints&.maximum(:iid) }
|
|
|
|
has_internal_id :iid, scope: :group, init: ->(s) { s&.group&.sprints&.maximum(:iid) }
|
2020-04-30 20:09:59 -04:00
|
|
|
|
|
|
|
state_machine :state, initial: :active do
|
|
|
|
event :close do
|
|
|
|
transition active: :closed
|
|
|
|
end
|
|
|
|
|
|
|
|
event :activate do
|
|
|
|
transition closed: :active
|
|
|
|
end
|
|
|
|
|
|
|
|
state :active, value: Sprint::STATE_ID_MAP[:active]
|
|
|
|
state :closed, value: Sprint::STATE_ID_MAP[:closed]
|
|
|
|
end
|
2020-04-23 17:09:31 -04:00
|
|
|
end
|