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, #email_subscribed?, 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_group_member, #notifiable_path, notify, notify_all, notify_to, #open!, open_all_of, #opened?, #optional_target_names, #optional_target_subscribed?, #optional_targets, #publish_to_optional_targets, #remove_from_group, send_batch_notification_email, #send_notification_email, #subscribed?, #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
73 74 75 76 |
# File 'lib/activity_notification/models/notification.rb', line 73 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.
178 |
# File 'lib/activity_notification/models/notification.rb', line 178 scope :filtered_by_group, ->(group) { where(group: group) } |
.filtered_by_instance ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects filtered notifications by notifiable instance.
162 |
# File 'lib/activity_notification/models/notification.rb', line 162 scope :filtered_by_instance, ->(notifiable) { where(notifiable: notifiable) } |
.filtered_by_key ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects filtered notifications by key.
186 |
# File 'lib/activity_notification/models/notification.rb', line 186 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.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/activity_notification/models/notification.rb', line 210 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) && .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
146 |
# File 'lib/activity_notification/models/notification.rb', line 146 scope :filtered_by_target, ->(target) { where(target: target) } |
.filtered_by_target_type ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects filtered notifications by target_type.
154 |
# File 'lib/activity_notification/models/notification.rb', line 154 scope :filtered_by_target_type, ->(target_type) { where(target_type: target_type) } |
.filtered_by_type ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects filtered notifications by notifiable_type.
170 |
# File 'lib/activity_notification/models/notification.rb', line 170 scope :filtered_by_type, ->(notifiable_type) { where(notifiable_type: notifiable_type) } |
.group_members_only ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects group member notifications only.
60 |
# File 'lib/activity_notification/models/notification.rb', line 60 scope :group_members_only, -> { where.not(group_owner_id: nil) } |
.group_owners_only ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects group owner notifications only.
55 |
# File 'lib/activity_notification/models/notification.rb', line 55 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
123 124 125 126 |
# File 'lib/activity_notification/models/notification.rb', line 123 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.
137 |
# File 'lib/activity_notification/models/notification.rb', line 137 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.
109 |
# File 'lib/activity_notification/models/notification.rb', line 109 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.
103 |
# File 'lib/activity_notification/models/notification.rb', line 103 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
94 95 96 97 |
# File 'lib/activity_notification/models/notification.rb', line 94 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.
131 |
# File 'lib/activity_notification/models/notification.rb', line 131 scope :unopened_index_group_members_only, -> { where(group_owner_id: unopened_index.map(&:id)) } |
.unopened_only ⇒ ActiveRecord_AssociationRelation<Notificaion>
Selects unopened notifications only.
81 |
# File 'lib/activity_notification/models/notification.rb', line 81 scope :unopened_only, -> { where(opened_at: nil) } |
Instance Method Details
#earliest ⇒ Notification
Returns earliest notification instance.
270 |
# File 'lib/activity_notification/models/notification.rb', line 270 scope :earliest, -> { earliest_order.first } |
#earliest_order ⇒ ActiveRecord_AssociationRelation<Notificaion>
Orders by earliest (older) first as created_at: :asc.
262 |
# File 'lib/activity_notification/models/notification.rb', line 262 scope :earliest_order, -> { order(created_at: :asc) } |
#group ⇒ Object
Belongs to group instance of this notification as polymorphic association.
24 |
# File 'lib/activity_notification/models/notification.rb', line 24 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.
38 |
# File 'lib/activity_notification/models/notification.rb', line 38 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.
31 |
# File 'lib/activity_notification/models/notification.rb', line 31 belongs_to :group_owner, class_name: :Notification |
#latest ⇒ Notification
Returns latest notification instance.
266 |
# File 'lib/activity_notification/models/notification.rb', line 266 scope :latest, -> { latest_order.first } |
#latest_order ⇒ ActiveRecord_AssociationRelation<Notificaion>
Orders by latest (newest) first as created_at: :desc.
258 |
# File 'lib/activity_notification/models/notification.rb', line 258 scope :latest_order, -> { order(created_at: :desc) } |
#notifiable ⇒ Object
Belongs to notifiable instance of this notification as polymorphic association.
19 |
# File 'lib/activity_notification/models/notification.rb', line 19 belongs_to :notifiable, polymorphic: true |
#notifier ⇒ Object
Belongs to :otifier instance of this notification.
43 |
# File 'lib/activity_notification/models/notification.rb', line 43 belongs_to :notifier, polymorphic: true |
#target ⇒ Object
Belongs to target instance of this notification as polymorphic association.
14 |
# File 'lib/activity_notification/models/notification.rb', line 14 belongs_to :target, polymorphic: true |
#with_group ⇒ ActiveRecord_AssociationRelation<Notificaion>
Includes group instance with query for notifications.
242 |
# File 'lib/activity_notification/models/notification.rb', line 242 scope :with_group, -> { includes(:group) } |
#with_group_members ⇒ ActiveRecord_AssociationRelation<Notificaion>
Includes group member instances with query for notifications.
250 |
# File 'lib/activity_notification/models/notification.rb', line 250 scope :with_group_members, -> { includes(:group_members) } |
#with_group_owner ⇒ ActiveRecord_AssociationRelation<Notificaion>
Includes group owner instances with query for notifications.
246 |
# File 'lib/activity_notification/models/notification.rb', line 246 scope :with_group_owner, -> { includes(:group_owner) } |
#with_notifiable ⇒ ActiveRecord_AssociationRelation<Notificaion>
Includes notifiable instance with query for notifications.
238 |
# File 'lib/activity_notification/models/notification.rb', line 238 scope :with_notifiable, -> { includes(:notifiable) } |
#with_notifier ⇒ ActiveRecord_AssociationRelation<Notificaion>
Includes notifier instance with query for notifications.
254 |
# File 'lib/activity_notification/models/notification.rb', line 254 scope :with_notifier, -> { includes(:notifier) } |
#with_target ⇒ ActiveRecord_AssociationRelation<Notificaion>
Includes target instance with query for notifications.
234 |
# File 'lib/activity_notification/models/notification.rb', line 234 scope :with_target, -> { includes(:target) } |