Sha256: 463f3d5fee34fd93df6882951c1c8655f2d17000d10743fa65d99c06ceb6702b

Contents?: true

Size: 848 Bytes

Versions: 1

Compression:

Stored size: 848 Bytes

Contents

module SimpleNotifications
  class Delivery < ActiveRecord::Base
    self.table_name = 'deliveries'

    # Class Attribute Accessors
    cattr_accessor :after_delivered, :after_read

    # Associations
    belongs_to :simple_notification,
               class_name: 'SimpleNotifications::Record',
               inverse_of: :deliveries
    belongs_to :receiver, polymorphic: true

    # Callbacks
    after_update_commit :after_create_actions

    private

    def after_create_actions
      if !!SimpleNotifications::Delivery.after_delivered && previous_changes['is_delivered'] == [false, true]
        SimpleNotifications::Delivery.after_delivered.call
      end

      if !!SimpleNotifications::Delivery.after_read && previous_changes['is_read'] == [false, true]
        SimpleNotifications::Delivery.after_read.call
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_notifications-1.1.0 lib/simple_notifications/app/models/delivery.rb