Sha256: 201209f62b38e1806faf7c530214cda2151e3d30f6863c645d92cdec2c4d4d49

Contents?: true

Size: 837 Bytes

Versions: 1

Compression:

Stored size: 837 Bytes

Contents

module Signum
  class Signal < ApplicationRecord
    belongs_to :signalable, polymorphic: true
    after_commit :signal

    validates :text, presence: true

    scope :pending, -> { with_state(:pending) }
    scope :shown, -> { with_state(:shown) }
    scope :closed, -> { with_state(:closed) }

    state_machine initial: :pending do
      state :pending
      state :broadcasted
      state :shown
      state :closed

      event :broadcast do
        transition any => :broadcasted
      end

      event :show do
        transition any => :shown
      end

      event :close do
        # We allow pending, sent and shown, because the user could close, before we process
        transition any => :closed
      end
    end

    private

    def signal
      Signum::SendSignalsJob.perform_later(self) if pending?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
signum-0.3.12 app/models/signum/signal.rb