Class: ActivityNotification::ORM::ActiveRecord::Notification

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Common, NotificationApi, Renderable
Defined in:
lib/activity_notification/orm/active_record/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, #group_owner?, 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 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

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



143
# File 'lib/activity_notification/orm/active_record/notification.rb', line 143

scope :earlier_than,                      ->(created_time) { where('created_at < ?', created_time) }

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

  • (ActiveRecord_AssociationRelation<Notificaion>)

    Database query of filtered notifications



127
# File 'lib/activity_notification/orm/active_record/notification.rb', line 127

scope :filtered_by_group,                 ->(group) { where(group: group) }

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

  • (ActiveRecord_AssociationRelation<Notificaion>)

    Database query of filtered notifications



119
# File 'lib/activity_notification/orm/active_record/notification.rb', line 119

scope :filtered_by_instance,              ->(notifiable) { where(notifiable: notifiable) }

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

  • (ActiveRecord_AssociationRelation<Notificaion>)

    Database query of filtered notifications



111
# File 'lib/activity_notification/orm/active_record/notification.rb', line 111

scope :filtered_by_target,                ->(target) { where(target: target) }

.group_members_of_owner_ids_onlyActiveRecord_AssociationRelation<Notificaion>

Selects group member notifications with specified group owner ids.

Parameters:

  • owner_ids (Array<String>)

    Array of group owner ids

Returns:

  • (ActiveRecord_AssociationRelation<Notificaion>)

    Database query of filtered notifications



102
# File 'lib/activity_notification/orm/active_record/notification.rb', line 102

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

.group_members_onlyActiveRecord_AssociationRelation<Notificaion>

Selects group member notifications only.

Returns:

  • (ActiveRecord_AssociationRelation<Notificaion>)

    Database query of filtered notifications



62
# File 'lib/activity_notification/orm/active_record/notification.rb', line 62

scope :group_members_only,                -> { where.not(group_owner_id: nil) }

.group_owners_onlyActiveRecord_AssociationRelation<Notificaion>

Selects group owner notifications only.

Returns:

  • (ActiveRecord_AssociationRelation<Notificaion>)

    Database query of filtered notifications



57
# File 'lib/activity_notification/orm/active_record/notification.rb', line 57

scope :group_owners_only,                 -> { where(group_owner_id: nil) }

.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



135
# File 'lib/activity_notification/orm/active_record/notification.rb', line 135

scope :later_than,                        ->(created_time) { where('created_at > ?', created_time) }

.opened_index_group_members_onlyActiveRecord_AssociationRelation<Notificaion>

Selects group member notifications in opened_index.

Parameters:

  • limit (Integer)

    Limit to query for opened notifications

Returns:

  • (ActiveRecord_AssociationRelation<Notificaion>)

    Database query of filtered notifications



90
# File 'lib/activity_notification/orm/active_record/notification.rb', line 90

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

.opened_onlyActiveRecord_AssociationRelation<Notificaion>

Selects opened notifications only with limit.

Parameters:

  • limit (Integer)

    Limit to query for opened notifications

Returns:

  • (ActiveRecord_AssociationRelation<Notificaion>)

    Database query of filtered notifications



79
# File 'lib/activity_notification/orm/active_record/notification.rb', line 79

scope :opened_only,                       ->(limit) { opened_only!.limit(limit) }

.opened_only!ActiveRecord_AssociationRelation<Notificaion>

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

Returns:

  • (ActiveRecord_AssociationRelation<Notificaion>)

    Database query of filtered notifications



73
# File 'lib/activity_notification/orm/active_record/notification.rb', line 73

scope :opened_only!,                      -> { where.not(opened_at: nil) }

.raise_delete_restriction_error(error_text) ⇒ void

This method returns an undefined value.

Raise DeleteRestrictionError for notifications.

Parameters:

  • error_text (String)

    Error text for raised exception

Raises:

  • (ActiveRecord::DeleteRestrictionError)

    DeleteRestrictionError from used ORM



173
174
175
# File 'lib/activity_notification/orm/active_record/notification.rb', line 173

def self.raise_delete_restriction_error(error_text)
  raise ::ActiveRecord::DeleteRestrictionError.new(error_text)
end

.unopened_index_group_members_onlyActiveRecord_AssociationRelation<Notificaion>

Selects group member notifications in unopened_index.

Returns:

  • (ActiveRecord_AssociationRelation<Notificaion>)

    Database query of filtered notifications



84
# File 'lib/activity_notification/orm/active_record/notification.rb', line 84

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

.unopened_onlyActiveRecord_AssociationRelation<Notificaion>

Selects unopened notifications only.

Returns:

  • (ActiveRecord_AssociationRelation<Notificaion>)

    Database query of filtered notifications



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

scope :unopened_only,                     -> { where(opened_at: nil) }

.within_expiration_onlyActiveRecord_AssociationRelation<Notificaion>

Selects notifications within expiration.

Parameters:

  • expiry_delay (ActiveSupport::Duration)

    Expiry period of notifications

Returns:

  • (ActiveRecord_AssociationRelation<Notificaion>)

    Database query of filtered notifications



96
# File 'lib/activity_notification/orm/active_record/notification.rb', line 96

scope :within_expiration_only,            ->(expiry_delay) { where("created_at > ?", expiry_delay.ago) }

Instance Method Details

#groupObject

Belongs to group instance of this notification as polymorphic association.

Returns:

  • (Object)

    Group instance of this notification



26
# File 'lib/activity_notification/orm/active_record/notification.rb', line 26

belongs_to :group,         polymorphic: true, optional: true

#group_membersActiveRecord_AssociationRelation<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:

  • (ActiveRecord_AssociationRelation<Notificaion>)

    Database query of the group member notification instances of this notification



40
# File 'lib/activity_notification/orm/active_record/notification.rb', line 40

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



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

belongs_to :group_owner,   class_name: "ActivityNotification::Notification", optional: true

#notifiableObject

Belongs to notifiable instance of this notification as polymorphic association.

Returns:

  • (Object)

    Notifiable instance of this notification



21
# File 'lib/activity_notification/orm/active_record/notification.rb', line 21

belongs_to :notifiable,    polymorphic: true

#notifierObject

Belongs to :notifier instance of this notification.

Returns:

  • (Object)

    Notifier instance of this notification



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

belongs_to :notifier,      polymorphic: true, optional: true

#targetObject

Belongs to target instance of this notification as polymorphic association.

Returns:

  • (Object)

    Target instance of this notification



16
# File 'lib/activity_notification/orm/active_record/notification.rb', line 16

belongs_to :target,        polymorphic: true

#with_groupActiveRecord_AssociationRelation<Notificaion>

Includes group instance with query for notifications.

Returns:

  • (ActiveRecord_AssociationRelation<Notificaion>)

    Database query of notifications with group



155
# File 'lib/activity_notification/orm/active_record/notification.rb', line 155

scope :with_group,                        -> { includes(:group) }

#with_group_membersActiveRecord_AssociationRelation<Notificaion>

Includes group member instances with query for notifications.

Returns:

  • (ActiveRecord_AssociationRelation<Notificaion>)

    Database query of notifications with group members



163
# File 'lib/activity_notification/orm/active_record/notification.rb', line 163

scope :with_group_members,                -> { includes(:group_members) }

#with_group_ownerActiveRecord_AssociationRelation<Notificaion>

Includes group owner instances with query for notifications.

Returns:

  • (ActiveRecord_AssociationRelation<Notificaion>)

    Database query of notifications with group owner



159
# File 'lib/activity_notification/orm/active_record/notification.rb', line 159

scope :with_group_owner,                  -> { includes(:group_owner) }

#with_notifiableActiveRecord_AssociationRelation<Notificaion>

Includes notifiable instance with query for notifications.

Returns:

  • (ActiveRecord_AssociationRelation<Notificaion>)

    Database query of notifications with notifiable



151
# File 'lib/activity_notification/orm/active_record/notification.rb', line 151

scope :with_notifiable,                   -> { includes(:notifiable) }

#with_notifierActiveRecord_AssociationRelation<Notificaion>

Includes notifier instance with query for notifications.

Returns:

  • (ActiveRecord_AssociationRelation<Notificaion>)

    Database query of notifications with notifier



167
# File 'lib/activity_notification/orm/active_record/notification.rb', line 167

scope :with_notifier,                     -> { includes(:notifier) }

#with_targetActiveRecord_AssociationRelation<Notificaion>

Includes target instance with query for notifications.

Returns:

  • (ActiveRecord_AssociationRelation<Notificaion>)

    Database query of notifications with target



147
# File 'lib/activity_notification/orm/active_record/notification.rb', line 147

scope :with_target,                       -> { includes(:target) }