Class: ActivityNotification::ORM::Dynamoid::Notification

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::AttributeAssignment, Association, Common, DynamoidExtension, NotificationApi, Renderable, Dynamoid::Document, GlobalID::Identification
Defined in:
lib/activity_notification/orm/dynamoid/notification.rb

Overview

Notification model implementation generated by ActivityNotification.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NotificationApi

all_index!, available_options, earliest, earliest!, #earliest_order, #earliest_order!, #email_subscribed?, filtered_by_key, filtered_by_options, filtered_by_target_type, filtered_by_type, generate_notification, #group_member?, #group_member_count, #group_member_exists?, group_member_exists?, #group_member_notifier_count, #group_member_notifier_exists?, #group_notification_count, #group_notifier_count, latest, latest!, #latest_group_member, #latest_order, #latest_order!, #notifiable_path, notify, notify_all, notify_all_later, notify_later, notify_later_to, notify_to, #open!, open_all_of, #opened?, opened_index, #optional_target_names, #optional_target_subscribed?, #optional_targets, #printable_notifiable_name, #publish_to_optional_targets, #remove_from_group, send_batch_notification_email, #send_notification_email, set_notification_mailer, #subscribed?, uniq_keys, #unopened?, unopened_index, valid_group_owner

Methods included from Association

belongs_to_composite_xdb_record, belongs_to_polymorphic_xdb_record, filtered_by_association, has_many_composite_xdb_records, has_many_polymorphic_xdb_records, has_many_records, #update

Methods included from Renderable

#layout_path, #partial_path, #prepare_assigns, #prepare_locals, #prepare_parameters, #render, #text

Methods included from Common

#printable_name, #printable_type, #resolve_value, #to_class_name, #to_resource_name, #to_resources_name

Methods included from DynamoidExtension

#becomes, delete_all

Class Method Details

.raise_delete_restriction_error(error_text) ⇒ void

This method returns an undefined value.

Raise ActivityNotification::DeleteRestrictionError for notifications.

Parameters:

  • error_text (String)

    Error text for raised exception

Raises:



161
162
163
# File 'lib/activity_notification/orm/dynamoid/notification.rb', line 161

def self.raise_delete_restriction_error(error_text)
  raise ActivityNotification::DeleteRestrictionError, error_text
end

Instance Method Details

#after_storeObject

Call after store action with stored notification



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/activity_notification/orm/dynamoid/notification.rb', line 91

def after_store
  if group_owner?
    self.stored_group_notification_count    = group_notification_count
    self.stored_group_member_notifier_count = group_member_notifier_count
    self.stored_group_members               = group_members.as_json
    self.stored_group_members.each do |group_member|
      # Cast Time and DateTime field to String to handle Dynamoid unsupported type error
      group_member.each do |k, v|
        group_member[k] = v.to_s if v.is_a?(Time) || v.is_a?(DateTime)
      end
    end
    save
  else
    group_owner.after_store
  end
end

#groupObject

Belongs to group instance of this notification as polymorphic association using composite key.

Returns:

  • (Object)

    Group instance of this notification



33
# File 'lib/activity_notification/orm/dynamoid/notification.rb', line 33

belongs_to_composite_xdb_record :group, store_with_associated_records: true, as_json_options: { methods: [:printable_type, :printable_group_name] }

#group_membersDynamoid::Criteria::Chain

Has many group member notification instances of this notification. Only group owner instance has :group_members value. Group member instance has nil as :group_members association. has_many :group_members, class_name: “ActivityNotification::Notification”, foreign_key: :group_owner_id

Returns:

  • (Dynamoid::Criteria::Chain)

    Database query of the group member notification instances of this notification



60
61
62
# File 'lib/activity_notification/orm/dynamoid/notification.rb', line 60

def group_members
  Notification.where(group_owner_id: id)
end

#group_ownerNotification

Customized method that belongs to group owner notification instance of this notification.

Returns:

  • (Notification)

    Group owner notification instance of this notification

Raises:

  • (Errors::RecordNotFound)

    Record not found error



45
# File 'lib/activity_notification/orm/dynamoid/notification.rb', line 45

belongs_to :group_owner, { class_name: "ActivityNotification::Notification", foreign_key: :group_owner_id, optional: true }

#group_owner?Boolean

Returns if the notification is group owner. Calls NotificationApi#group_owner? as super method.

Returns:

  • (Boolean)

    If the notification is group owner



153
154
155
# File 'lib/activity_notification/orm/dynamoid/notification.rb', line 153

def group_owner?
  super
end

#notifiableObject

Belongs to notifiable instance of this notification as polymorphic association using composite key.

Returns:

  • (Object)

    Notifiable instance of this notification



28
# File 'lib/activity_notification/orm/dynamoid/notification.rb', line 28

belongs_to_composite_xdb_record :notifiable, store_with_associated_records: true, as_json_options: { methods: [:printable_type] }

#notifierObject

Belongs to :otifier instance of this notification.

Returns:

  • (Object)

    Notifier instance of this notification



67
# File 'lib/activity_notification/orm/dynamoid/notification.rb', line 67

belongs_to_composite_xdb_record :notifier, store_with_associated_records: true, as_json_options: { methods: [:printable_type, :printable_notifier_name] }

#prepare_to_storeObject

Returns prepared notification object to store

Returns:

  • (Object)

    prepared notification object to store



79
80
81
82
83
84
85
86
87
88
# File 'lib/activity_notification/orm/dynamoid/notification.rb', line 79

def prepare_to_store
  self.stored_notifiable_path           = notifiable_path
  self.stored_printable_notifiable_name = printable_notifiable_name
  if group_owner?
    self.stored_group_notification_count    = 0
    self.stored_group_member_notifier_count = 0
    self.stored_group_members               = []
  end
  self
end

#targetObject

Belongs to target instance of this notification as polymorphic association using composite key.

Returns:

  • (Object)

    Target instance of this notification



23
# File 'lib/activity_notification/orm/dynamoid/notification.rb', line 23

belongs_to_composite_xdb_record :target, store_with_associated_records: true, as_json_options: { methods: [:printable_type, :printable_target_name] }