Class: ActivityNotification::Notification
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ActivityNotification::Notification
- Includes:
- Common, NotificationApi, Renderable
- Defined in:
- lib/activity_notification/models/notification.rb
Overview
Notification model implementation generated by ActivityNotification.
Class Method Summary collapse
-
.all_index! ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects all notification index.
-
.filtered_by_group ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects filtered notifications by group instance.
-
.filtered_by_instance ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects filtered notifications by notifiable instance.
-
.filtered_by_key ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects filtered notifications by key.
-
.filtered_by_options ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects filtered notifications by notifiable_type, group or key with filter options.
-
.filtered_by_target ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects filtered notifications by target instance.
-
.filtered_by_target_type ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects filtered notifications by target_type.
-
.filtered_by_type ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects filtered notifications by notifiable_type.
-
.group_members_only ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects group member notifications only.
-
.group_owners_only ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects group owner notifications only.
-
.opened_index ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects unopened notification index.
-
.opened_index_group_members_only ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects group member notifications in opened_index.
-
.opened_only ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects opened notifications only with limit.
-
.opened_only! ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects opened notifications only without limit.
-
.unopened_index ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects unopened notification index.
-
.unopened_index_group_members_only ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects group member notifications in unopened_index.
-
.unopened_only ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects unopened notifications only.
Instance Method Summary collapse
-
#earliest ⇒ Notification
Returns earliest notification instance.
-
#earliest_order ⇒ ActiveRecord_AssociationRelation<Notificaion>
Orders by earliest (older) first as created_at: :asc.
-
#group ⇒ Object
Belongs to group instance of this notification as polymorphic association.
-
#group_members ⇒ ActiveRecord_AssociationRelation<Notificaion>
Has many group member notification instances of this notification.
-
#group_owner ⇒ Notification
Belongs to group owner notification instance of this notification.
-
#latest ⇒ Notification
Returns latest notification instance.
-
#latest_order ⇒ ActiveRecord_AssociationRelation<Notificaion>
Orders by latest (newest) first as created_at: :desc.
-
#notifiable ⇒ Object
Belongs to notifiable instance of this notification as polymorphic association.
-
#notifier ⇒ Object
Belongs to :otifier instance of this notification.
-
#target ⇒ Object
Belongs to target instance of this notification as polymorphic association.
-
#with_group ⇒ ActiveRecord_AssociationRelation<Notificaion>
Includes group instance with query for notifications.
-
#with_group_members ⇒ ActiveRecord_AssociationRelation<Notificaion>
Includes group member instances with query for notifications.
-
#with_group_owner ⇒ ActiveRecord_AssociationRelation<Notificaion>
Includes group owner instances with query for notifications.
-
#with_notifiable ⇒ ActiveRecord_AssociationRelation<Notificaion>
Includes notifiable instance with query for notifications.
-
#with_notifier ⇒ ActiveRecord_AssociationRelation<Notificaion>
Includes notifier instance with query for notifications.
-
#with_target ⇒ ActiveRecord_AssociationRelation<Notificaion>
Includes target instance with query for notifications.
Methods included from NotificationApi
available_options, #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_group_member, #notifiable_path, notify, notify_all, notify_to, #open!, open_all_of, #opened?, send_batch_notification_email, #send_notification_email, #unopened?
Methods included from Common
#printable_name, #printable_type, #resolve_value, #to_class_name, #to_resource_name, #to_resources_name
Methods included from Renderable
#layout_path, #partial_path, #prepare_locals, #prepare_parameters, #render, #text
Class Method Details
.all_index! ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects all notification index.
ActivityNotification::Notification.all_index!
is defined same as
ActivityNotification::Notification.group_owners_only.latest_order
71 72 73 74 |
# File 'lib/activity_notification/models/notification.rb', line 71 scope :all_index!, ->(reverse = false, with_group_members = false) { target_index = with_group_members ? self : group_owners_only reverse ? target_index.earliest_order : target_index.latest_order } |
.filtered_by_group ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects filtered notifications by group instance.
176 |
# File 'lib/activity_notification/models/notification.rb', line 176 scope :filtered_by_group, ->(group) { where(group: group) } |
.filtered_by_instance ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects filtered notifications by notifiable instance.
160 |
# File 'lib/activity_notification/models/notification.rb', line 160 scope :filtered_by_instance, ->(notifiable) { where(notifiable: notifiable) } |
.filtered_by_key ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects filtered notifications by key.
184 |
# File 'lib/activity_notification/models/notification.rb', line 184 scope :filtered_by_key, ->(key) { where(key: key) } |
.filtered_by_options ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects filtered notifications by notifiable_type, group or key with filter options.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/activity_notification/models/notification.rb', line 208 scope :filtered_by_options, ->( = {}) { = ActivityNotification.cast_to_indifferent_hash() filtered_notifications = all if .has_key?(:filtered_by_type) filtered_notifications = filtered_notifications.filtered_by_type([:filtered_by_type]) end if .has_key?(:filtered_by_group) filtered_notifications = filtered_notifications.filtered_by_group([:filtered_by_group]) end if .has_key?(:filtered_by_group_type) and .has_key?(:filtered_by_group_id) filtered_notifications = filtered_notifications .where(group_type: [:filtered_by_group_type], group_id: [:filtered_by_group_id]) end if .has_key?(:filtered_by_key) filtered_notifications = filtered_notifications.filtered_by_key([:filtered_by_key]) end if .has_key?(:custom_filter) filtered_notifications = filtered_notifications.where([:custom_filter]) end filtered_notifications } |
.filtered_by_target ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects filtered notifications by target instance.
ActivityNotification::Notification.filtered_by_target(@user)
is the same as
@user.notifications
144 |
# File 'lib/activity_notification/models/notification.rb', line 144 scope :filtered_by_target, ->(target) { where(target: target) } |
.filtered_by_target_type ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects filtered notifications by target_type.
152 |
# File 'lib/activity_notification/models/notification.rb', line 152 scope :filtered_by_target_type, ->(target_type) { where(target_type: target_type) } |
.filtered_by_type ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects filtered notifications by notifiable_type.
168 |
# File 'lib/activity_notification/models/notification.rb', line 168 scope :filtered_by_type, ->(notifiable_type) { where(notifiable_type: notifiable_type) } |
.group_members_only ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects group member notifications only.
58 |
# File 'lib/activity_notification/models/notification.rb', line 58 scope :group_members_only, -> { where.not(group_owner_id: nil) } |
.group_owners_only ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects group owner notifications only.
53 |
# File 'lib/activity_notification/models/notification.rb', line 53 scope :group_owners_only, -> { where(group_owner_id: nil) } |
.opened_index ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects unopened notification index.
ActivityNotification::Notification.opened_index(limit)
is defined same as
ActivityNotification::Notification.opened_only(limit).group_owners_only.latest_order
121 122 123 124 |
# File 'lib/activity_notification/models/notification.rb', line 121 scope :opened_index, ->(limit, reverse = false, with_group_members = false) { target_index = with_group_members ? opened_only(limit) : opened_only(limit).group_owners_only reverse ? target_index.earliest_order : target_index.latest_order } |
.opened_index_group_members_only ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects group member notifications in opened_index.
135 |
# File 'lib/activity_notification/models/notification.rb', line 135 scope :opened_index_group_members_only, ->(limit) { where(group_owner_id: opened_index(limit).map(&:id)) } |
.opened_only ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects opened notifications only with limit.
107 |
# File 'lib/activity_notification/models/notification.rb', line 107 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.
101 |
# File 'lib/activity_notification/models/notification.rb', line 101 scope :opened_only!, -> { where.not(opened_at: nil) } |
.unopened_index ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects unopened notification index.
ActivityNotification::Notification.unopened_index
is defined same as
ActivityNotification::Notification.unopened_only.group_owners_only.latest_order
92 93 94 95 |
# File 'lib/activity_notification/models/notification.rb', line 92 scope :unopened_index, ->(reverse = false, with_group_members = false) { target_index = with_group_members ? unopened_only : unopened_only.group_owners_only reverse ? target_index.earliest_order : target_index.latest_order } |
.unopened_index_group_members_only ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects group member notifications in unopened_index.
129 |
# File 'lib/activity_notification/models/notification.rb', line 129 scope :unopened_index_group_members_only, -> { where(group_owner_id: unopened_index.map(&:id)) } |
.unopened_only ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects unopened notifications only.
79 |
# File 'lib/activity_notification/models/notification.rb', line 79 scope :unopened_only, -> { where(opened_at: nil) } |
Instance Method Details
#earliest ⇒ Notification
Returns earliest notification instance.
268 |
# File 'lib/activity_notification/models/notification.rb', line 268 scope :earliest, -> { earliest_order.first } |
#earliest_order ⇒ ActiveRecord_AssociationRelation<Notificaion>
Orders by earliest (older) first as created_at: :asc.
260 |
# File 'lib/activity_notification/models/notification.rb', line 260 scope :earliest_order, -> { order(created_at: :asc) } |
#group ⇒ Object
Belongs to group instance of this notification as polymorphic association.
22 |
# File 'lib/activity_notification/models/notification.rb', line 22 belongs_to :group, polymorphic: true |
#group_members ⇒ ActiveRecord_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.
36 |
# File 'lib/activity_notification/models/notification.rb', line 36 has_many :group_members, class_name: :Notification, foreign_key: :group_owner_id |
#group_owner ⇒ Notification
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.
29 |
# File 'lib/activity_notification/models/notification.rb', line 29 belongs_to :group_owner, class_name: :Notification |
#latest ⇒ Notification
Returns latest notification instance.
264 |
# File 'lib/activity_notification/models/notification.rb', line 264 scope :latest, -> { latest_order.first } |
#latest_order ⇒ ActiveRecord_AssociationRelation<Notificaion>
Orders by latest (newest) first as created_at: :desc.
256 |
# File 'lib/activity_notification/models/notification.rb', line 256 scope :latest_order, -> { order(created_at: :desc) } |
#notifiable ⇒ Object
Belongs to notifiable instance of this notification as polymorphic association.
17 |
# File 'lib/activity_notification/models/notification.rb', line 17 belongs_to :notifiable, polymorphic: true |
#notifier ⇒ Object
Belongs to :otifier instance of this notification.
41 |
# File 'lib/activity_notification/models/notification.rb', line 41 belongs_to :notifier, polymorphic: true |
#target ⇒ Object
Belongs to target instance of this notification as polymorphic association.
12 |
# File 'lib/activity_notification/models/notification.rb', line 12 belongs_to :target, polymorphic: true |
#with_group ⇒ ActiveRecord_AssociationRelation<Notificaion>
Includes group instance with query for notifications.
240 |
# File 'lib/activity_notification/models/notification.rb', line 240 scope :with_group, -> { includes(:group) } |
#with_group_members ⇒ ActiveRecord_AssociationRelation<Notificaion>
Includes group member instances with query for notifications.
248 |
# File 'lib/activity_notification/models/notification.rb', line 248 scope :with_group_members, -> { includes(:group_members) } |
#with_group_owner ⇒ ActiveRecord_AssociationRelation<Notificaion>
Includes group owner instances with query for notifications.
244 |
# File 'lib/activity_notification/models/notification.rb', line 244 scope :with_group_owner, -> { includes(:group_owner) } |
#with_notifiable ⇒ ActiveRecord_AssociationRelation<Notificaion>
Includes notifiable instance with query for notifications.
236 |
# File 'lib/activity_notification/models/notification.rb', line 236 scope :with_notifiable, -> { includes(:notifiable) } |
#with_notifier ⇒ ActiveRecord_AssociationRelation<Notificaion>
Includes notifier instance with query for notifications.
252 |
# File 'lib/activity_notification/models/notification.rb', line 252 scope :with_notifier, -> { includes(:notifier) } |
#with_target ⇒ ActiveRecord_AssociationRelation<Notificaion>
Includes target instance with query for notifications.
232 |
# File 'lib/activity_notification/models/notification.rb', line 232 scope :with_target, -> { includes(:target) } |