Class: Notification

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
AASM
Defined in:
app/models/notification.rb

Overview

create_table :notifications do |t|

t.string :type
t.references :created_by
t.text :message
t.references :notification_type
t.string :current_state
t.text :custom_fields

t.timestamps

end

add_index :notifications, :notification_type_id add_index :notifications, :created_by_id add_index :notifications, :type

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_notification_of_type(notification_type, custom_fields = {}, created_by = nil) ⇒ Object

Creates a Notification record with the notification type passed

Parameters:

  • the (NotificationType | String)

    notification type to set, can be a NotificationType record or InternalIdentifier

  • custom (Hash)

    fields to set on the notification

  • the (Party)

    party that created the notification



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/notification.rb', line 45

def create_notification_of_type(notification_type, custom_fields={}, created_by=nil)
  notification_type = notification_type.class == NotificationType ? notification_type : NotificationType.iid(notification_type)

  notification = self.create(
      created_by: created_by,
      notification_type: notification_type
  )

  notification.custom_fields = custom_fields

  notification.save!

  notification
end

Instance Method Details

#deliver_notificationObject

Delivers notification, called by the notifications delayed job this is a template method and should be overridden by sub class



65
66
# File 'app/models/notification.rb', line 65

def deliver_notification
end