Sha256: 2c2e039bd0aa7205a462362917b8a4131756e80e8545ad9fe8b2e0597269c653

Contents?: true

Size: 1.38 KB

Versions: 16

Compression:

Stored size: 1.38 KB

Contents

module Marty
  module Notifications
    class Delivery < Marty::Base
      self.table_name = 'marty_notifications_deliveries'

      belongs_to :notification, class_name: '::Marty::Notifications::Notification'
      belongs_to :recipient, class_name: '::Marty::User'

      validates :state, presence: true

      # One delivery per type per notification for user
      validates :delivery_type,
                presence: true,
                uniqueness: { scope: [:notification_id, :recipient_id] }

      state_machine :delivery_type, initial: :web do
        state :web do
          def processor
            Marty::Notifications::Processors::Web
          end
        end

        # state :email do
        # def processor
        # Marty::Notifications::Processors::Email
        # end
        # end
        #
        # state :sms do
        # def processor
        # Marty::Notifications::Processors::Sms
        # end
        # end
      end

      state_machine :state, initial: :pending do
        state :pending
        state :sent
        state :delivered
        state :failed

        event :set_sent do
          transition [:pending, :failed] => :sent, sent: same
        end

        event :set_failed do
          transition [:pending, :sent] => :failed, failed: same
        end

        event :set_delivered do
          transition all => :delivered
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
marty-14.3.0 app/models/marty/notifications/delivery.rb
marty-14.0.0 app/models/marty/notifications/delivery.rb
marty-13.0.2 app/models/marty/notifications/delivery.rb
marty-11.0.0 app/models/marty/notifications/delivery.rb
marty-10.0.3 app/models/marty/notifications/delivery.rb
marty-10.0.2 app/models/marty/notifications/delivery.rb
marty-10.0.0 app/models/marty/notifications/delivery.rb
marty-9.5.1 app/models/marty/notifications/delivery.rb
marty-9.5.0 app/models/marty/notifications/delivery.rb
marty-9.3.3 app/models/marty/notifications/delivery.rb
marty-9.3.2 app/models/marty/notifications/delivery.rb
marty-9.3.0 app/models/marty/notifications/delivery.rb
marty-8.5.0 app/models/marty/notifications/delivery.rb
marty-8.4.1 app/models/marty/notifications/delivery.rb
marty-8.3.1 app/models/marty/notifications/delivery.rb
marty-8.2.0 app/models/marty/notifications/delivery.rb