Sha256: fef65898026343e92075c5ed7bf31a0f8366d220d63c4946fa63138194135d0b
Contents?: true
Size: 851 Bytes
Versions: 24
Compression:
Stored size: 851 Bytes
Contents
# frozen_string_literal: true class Trigger < ApplicationRecord belongs_to :pending_item, polymorphic: true class << self def post_action(due_at, item, method = "came_due") create!(due_at: due_at, pending_item: item, trigger_method: method) fire end def fire where("due_at <= ?", Time.zone.now).destroy_all true end def remove(pending_item, conditions = {}) return if pending_item.new_record? conditions = conditions.merge(pending_item_id: pending_item.id, pending_item_type: pending_item.class.to_s) where(conditions).delete_all end end # TODO: Ensure errors bubble up to where they are visible before_destroy :trigger_pending_item def trigger_pending_item pending_item&.send(trigger_method) true end end
Version data entries
24 entries across 24 versions & 2 rubygems