Class: ActivityNotification::ORM::Mongoid::Notification

Inherits:
Object
  • Object
show all
Includes:
Association, Common, NotificationApi, Renderable, GlobalID::Identification, Mongoid::Attributes::Dynamic, Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/activity_notification/orm/mongoid/notification.rb

Overview

Notification model implementation generated by ActivityNotification.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NotificationApi

#after_store, 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, #prepare_to_store, #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 Mongoid::Document

#as_json

Class Method Details

.earlier_thanActiveRecord_AssociationRelation<Notificaion>, Mongoid::Criteria<Notificaion>

Selects filtered notifications earlier than specified time.

Examples:

Get filtered unopened notificatons of the @user earlier than @notification

@notifications = @user.notifications.unopened_only.earlier_than(@notification.created_at)

Parameters:

  • Created (Time)

    time of the notifications for filter

Returns:

  • (ActiveRecord_AssociationRelation<Notificaion>, Mongoid::Criteria<Notificaion>)

    Database query of filtered notifications



162
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 162

scope :earlier_than,                      ->(created_time) { where(:created_at.lt => created_time) }

.filtered_by_groupMongoid::Criteria<Notificaion>

Selects filtered notifications by group instance.

Examples:

Get filtered unopened notificatons of the @user for @article as group

@notifications = @user.notifications.unopened_only.filtered_by_group(@article)

Parameters:

  • group (Object)

    Group instance for filter

Returns:

  • (Mongoid::Criteria<Notificaion>)

    Database query of filtered notifications



140
141
142
143
144
145
146
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 140

scope :filtered_by_group,                 ->(group) {
  group.present? ?
    where(group_id: group.id, group_type: group.class.name) :
    Gem::Version.new(::Mongoid::VERSION) >= Gem::Version.new('7.1.0') ?
      where(:group_id.exists => false, :group_type.exists => false).or(group_id: nil, group_type: nil) :
      any_of({ :group_id.exists => false, :group_type.exists => false }, { group_id: nil, group_type: nil })
}

.filtered_by_instanceMongoid::Criteria<Notificaion>

Selects filtered notifications by notifiable instance.

Examples:

Get filtered unopened notificatons of the @user for @comment as notifiable

@notifications = @user.notifications.unopened_only.filtered_by_instance(@comment)

Parameters:

  • notifiable (Object)

    Notifiable instance for filter

Returns:

  • (Mongoid::Criteria<Notificaion>)

    Database query of filtered notifications



132
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 132

scope :filtered_by_instance,              ->(notifiable) { filtered_by_association("notifiable", notifiable) }

.filtered_by_targetMongoid::Criteria<Notificaion>

Selects filtered notifications by target instance.

ActivityNotification::Notification.filtered_by_target(@user)

is the same as

@user.notifications

Parameters:

  • target (Object)

    Target instance for filter

Returns:

  • (Mongoid::Criteria<Notificaion>)

    Database query of filtered notifications



124
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 124

scope :filtered_by_target,                ->(target) { filtered_by_association("target", target) }

.group_members_of_owner_ids_onlyMongoid::Criteria<Notificaion>

Selects group member notifications with specified group owner ids.

Parameters:

  • owner_ids (Array<String>)

    Array of group owner ids

Returns:

  • (Mongoid::Criteria<Notificaion>)

    Database query of filtered notifications



115
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 115

scope :group_members_of_owner_ids_only,   ->(owner_ids) { where(:group_owner_id.in => owner_ids) }

.group_members_onlyMongoid::Criteria<Notificaion>

Selects group member notifications only.

Returns:

  • (Mongoid::Criteria<Notificaion>)

    Database query of filtered notifications



75
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 75

scope :group_members_only,                -> { where(:group_owner_id.exists => true) }

.group_owners_onlyMongoid::Criteria<Notificaion>

Selects group owner notifications only.

Returns:

  • (Mongoid::Criteria<Notificaion>)

    Database query of filtered notifications



70
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 70

scope :group_owners_only,                 -> { where(:group_owner_id.exists => false) }

.later_thanActiveRecord_AssociationRelation<Notificaion>, Mongoid::Criteria<Notificaion>

Selects filtered notifications later than specified time.

Examples:

Get filtered unopened notificatons of the @user later than @notification

@notifications = @user.notifications.unopened_only.later_than(@notification.created_at)

Parameters:

  • Created (Time)

    time of the notifications for filter

Returns:

  • (ActiveRecord_AssociationRelation<Notificaion>, Mongoid::Criteria<Notificaion>)

    Database query of filtered notifications



154
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 154

scope :later_than,                        ->(created_time) { where(:created_at.gt => created_time) }

.opened_index_group_members_onlyMongoid::Criteria<Notificaion>

Selects group member notifications in opened_index.

Parameters:

  • limit (Integer)

    Limit to query for opened notifications

Returns:

  • (Mongoid::Criteria<Notificaion>)

    Database query of filtered notifications



103
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 103

scope :opened_index_group_members_only,   ->(limit) { where(:group_owner_id.in => opened_index(limit).map(&:id)) }

.opened_onlyMongoid::Criteria<Notificaion>

Selects opened notifications only with limit.

Parameters:

  • limit (Integer)

    Limit to query for opened notifications

Returns:

  • (Mongoid::Criteria<Notificaion>)

    Database query of filtered notifications



92
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 92

scope :opened_only,                       ->(limit) { limit == 0 ? none : opened_only!.limit(limit) }

.opened_only!Mongoid::Criteria<Notificaion>

Selects opened notifications only without limit. Be careful to get too many records with this method.

Returns:

  • (Mongoid::Criteria<Notificaion>)

    Database query of filtered notifications



86
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 86

scope :opened_only!,                      -> { where(:opened_at.exists => true) }

.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:



202
203
204
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 202

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

.unopened_index_group_members_onlyMongoid::Criteria<Notificaion>

Selects group member notifications in unopened_index.

Returns:

  • (Mongoid::Criteria<Notificaion>)

    Database query of filtered notifications



97
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 97

scope :unopened_index_group_members_only, -> { where(:group_owner_id.in => unopened_index.map(&:id)) }

.unopened_onlyMongoid::Criteria<Notificaion>

Selects unopened notifications only.

Returns:

  • (Mongoid::Criteria<Notificaion>)

    Database query of filtered notifications



80
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 80

scope :unopened_only,                     -> { where(:opened_at.exists => false) }

.within_expiration_onlyMongoid::Criteria<Notificaion>

Selects notifications within expiration.

Parameters:

  • expiry_delay (ActiveSupport::Duration)

    Expiry period of notifications

Returns:

  • (Mongoid::Criteria<Notificaion>)

    Database query of filtered notifications



109
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 109

scope :within_expiration_only,            ->(expiry_delay) { where(:created_at.gt => expiry_delay.ago) }

Instance Method Details

#groupObject

Belongs to group instance of this notification as polymorphic association.

Returns:

  • (Object)

    Group instance of this notification



32
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 32

belongs_to_polymorphic_xdb_record :group, as_json_options: { methods: [:printable_type, :printable_group_name] }

#group_membersMongoid::Criteria<Notificaion>

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.

Returns:

  • (Mongoid::Criteria<Notificaion>)

    Database query of the group member notification instances of this notification



51
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 51

has_many   :group_members, class_name: "ActivityNotification::Notification", foreign_key: :group_owner_id

#group_ownerNotification

Belongs to group owner notification instance of this notification. Only group member instance has :group_owner value. Group owner instance has nil as :group_owner association.

Returns:

  • (Notification)

    Group owner notification instance of this notification



44
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 44

belongs_to :group_owner, { class_name: "ActivityNotification::Notification", 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



194
195
196
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 194

def group_owner?
  super
end

#notifiableObject

Belongs to notifiable instance of this notification as polymorphic association.

Returns:

  • (Object)

    Notifiable instance of this notification



27
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 27

belongs_to_polymorphic_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



56
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 56

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

#targetObject

Belongs to target instance of this notification as polymorphic association.

Returns:

  • (Object)

    Target instance of this notification



22
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 22

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

#whereMongoid::Criteria<Notification>

Selects filtered notifications by type of the object. Filtering with ActivityNotification::Notification is defined as default scope.

Returns:

  • (Mongoid::Criteria<Notification>)

    Database query of filtered notifications



65
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 65

default_scope -> { where(_type: "ActivityNotification::Notification") }

#with_groupMongoid::Criteria<Notificaion>

Includes group instance with query for notifications.

Returns:

  • (Mongoid::Criteria<Notificaion>)

    Database query of notifications with group



174
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 174

scope :with_group,                        -> { }

#with_group_membersMongoid::Criteria<Notificaion>

Includes group member instances with query for notifications.

Returns:

  • (Mongoid::Criteria<Notificaion>)

    Database query of notifications with group members



182
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 182

scope :with_group_members,                -> { }

#with_group_ownerMongoid::Criteria<Notificaion>

Includes group owner instances with query for notifications.

Returns:

  • (Mongoid::Criteria<Notificaion>)

    Database query of notifications with group owner



178
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 178

scope :with_group_owner,                  -> { }

#with_notifiableMongoid::Criteria<Notificaion>

Includes notifiable instance with query for notifications.

Returns:

  • (Mongoid::Criteria<Notificaion>)

    Database query of notifications with notifiable



170
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 170

scope :with_notifiable,                   -> { }

#with_notifierMongoid::Criteria<Notificaion>

Includes notifier instance with query for notifications.

Returns:

  • (Mongoid::Criteria<Notificaion>)

    Database query of notifications with notifier



186
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 186

scope :with_notifier,                     -> { }

#with_targetMongoid::Criteria<Notificaion>

Includes target instance with query for notifications.

Returns:

  • (Mongoid::Criteria<Notificaion>)

    Database query of notifications with target



166
# File 'lib/activity_notification/orm/mongoid/notification.rb', line 166

scope :with_target,                       -> { }