Class: ActivityNotification::ORM::Dynamoid::Notification
- Inherits:
-
Object
- Object
- ActivityNotification::ORM::Dynamoid::Notification
- 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
-
.raise_delete_restriction_error(error_text) ⇒ void
Raise ActivityNotification::DeleteRestrictionError for notifications.
Instance Method Summary collapse
-
#after_store ⇒ Object
Call after store action with stored notification.
-
#group ⇒ Object
Belongs to group instance of this notification as polymorphic association using composite key.
-
#group_members ⇒ Dynamoid::Criteria::Chain
Has many group member notification instances of this notification.
-
#group_owner ⇒ Notification
Customized method that belongs to group owner notification instance of this notification.
-
#group_owner=(notification) ⇒ Object
Setter method for group_owner association.
-
#group_owner? ⇒ Boolean
Returns if the notification is group owner.
-
#notifiable ⇒ Object
Belongs to notifiable instance of this notification as polymorphic association using composite key.
-
#notifier ⇒ Object
Belongs to :otifier instance of this notification.
-
#prepare_to_store ⇒ Object
Returns prepared notification object to store.
-
#reload ⇒ Object
Override reload method to refresh the record from database.
-
#target ⇒ Object
Belongs to target instance of this notification as polymorphic association using composite key.
Methods included from NotificationApi
all_index!, available_options, destroy_all_of, 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
Class Method Details
.raise_delete_restriction_error(error_text) ⇒ void
This method returns an undefined value.
Raise ActivityNotification::DeleteRestrictionError for notifications.
178 179 180 |
# File 'lib/activity_notification/orm/dynamoid/notification.rb', line 178 def self.raise_delete_restriction_error(error_text) raise ActivityNotification::DeleteRestrictionError, error_text end |
Instance Method Details
#after_store ⇒ Object
Call after store action with stored notification
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/activity_notification/orm/dynamoid/notification.rb', line 108 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 |
#group ⇒ Object
Belongs to group instance of this notification as polymorphic association using composite key.
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_members ⇒ Dynamoid::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
77 78 79 |
# File 'lib/activity_notification/orm/dynamoid/notification.rb', line 77 def group_members Notification.where(group_owner_id: id) end |
#group_owner ⇒ Notification
Customized method that belongs to group owner notification instance of this notification.
50 51 52 |
# File 'lib/activity_notification/orm/dynamoid/notification.rb', line 50 def group_owner group_owner_id.nil? ? nil : Notification.find(group_owner_id, raise_error: false) end |
#group_owner=(notification) ⇒ Object
Setter method for group_owner association
56 57 58 |
# File 'lib/activity_notification/orm/dynamoid/notification.rb', line 56 def group_owner=(notification) self.group_owner_id = notification.nil? ? nil : notification.id end |
#group_owner? ⇒ Boolean
Returns if the notification is group owner. Calls NotificationApi#group_owner? as super method.
170 171 172 |
# File 'lib/activity_notification/orm/dynamoid/notification.rb', line 170 def group_owner? super end |
#notifiable ⇒ Object
Belongs to notifiable instance of this notification as polymorphic association using composite key.
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] } |
#notifier ⇒ Object
Belongs to :otifier instance of this notification.
84 |
# File 'lib/activity_notification/orm/dynamoid/notification.rb', line 84 belongs_to_composite_xdb_record :notifier, store_with_associated_records: true, as_json_options: { methods: [:printable_type, :printable_notifier_name] } |
#prepare_to_store ⇒ Object
Returns prepared notification object to store
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/activity_notification/orm/dynamoid/notification.rb', line 96 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 |
#reload ⇒ Object
Override reload method to refresh the record from database
61 62 63 64 65 66 67 68 69 |
# File 'lib/activity_notification/orm/dynamoid/notification.rb', line 61 def reload fresh_record = self.class.find(id) if fresh_record # Update specific attributes we care about self.group_owner_id = fresh_record.group_owner_id self.opened_at = fresh_record.opened_at end self end |
#target ⇒ Object
Belongs to target instance of this notification as polymorphic association using composite key.
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] } |