Files
fizzy/app/models/card/postponable.rb
T
2025-10-15 13:44:49 +02:00

44 lines
803 B
Ruby

module Card::Postponable
extend ActiveSupport::Concern
included do
has_one :not_now, dependent: :destroy, class_name: "Card::NotNow"
scope :postponed, -> { open.published.joins(:not_now) }
scope :active, -> { open.published.where.missing(:not_now) }
end
def postponed?
open? && published? && not_now.present?
end
def postponed_at
not_now&.created_at
end
def postponed_by
not_now&.user
end
def active?
open? && published? && !postponed?
end
def postpone(user: Current.user)
transaction do
send_back_to_triage
reopen
activity_spike&.destroy
create_not_now!(user: user) unless postponed?
end
end
def resume
transaction do
reopen
activity_spike&.destroy
not_now&.destroy
end
end
end