class ActivityNotification::ORM::ActiveRecord::Notification
Notification
model implementation generated by ActivityNotification
.
Public Class Methods
Raise DeleteRestrictionError
for notifications. @param [String] error_text Error text for raised exception @raise [ActiveRecord::DeleteRestrictionError] DeleteRestrictionError
from used ORM
@return [void]
# 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
Protected Instance Methods
Returns count of group members of the opened notification. This method is designed to cache group by query result to avoid N+1 call. @api protected
@param [Integer] limit Limit to query for opened notifications @return [Integer] Count of group members of the opened notification
# File lib/activity_notification/orm/active_record/notification.rb, line 199 def opened_group_member_count(limit = ActivityNotification.config.opened_index_limit) # Cache group by query result to avoid N+1 call opened_group_member_counts = target.notifications .opened_index_group_members_only(limit) .group(:group_owner_id) .count count = opened_group_member_counts[id] || 0 count > limit ? limit : count end
Returns count of group member notifiers of the opened notification not including group owner notifier. This method is designed to cache group by query result to avoid N+1 call. @api protected
@param [Integer] limit Limit to query for opened notifications @return [Integer] Count of group member notifiers of the opened notification
# File lib/activity_notification/orm/active_record/notification.rb, line 233 def opened_group_member_notifier_count(limit = ActivityNotification.config.opened_index_limit) # Cache group by query result to avoid N+1 call opened_group_member_notifier_counts = target.notifications .opened_index_group_members_only(limit) .includes(:group_owner) .where("group_owners_#{self.class.table_name}.notifier_type = #{self.class.table_name}.notifier_type") .where.not("group_owners_#{self.class.table_name}.notifier_id = #{self.class.table_name}.notifier_id") .references(:group_owner) .group(:group_owner_id, :notifier_type) .count("distinct #{self.class.table_name}.notifier_id") count = opened_group_member_notifier_counts[[id, notifier_type]] || 0 count > limit ? limit : count end
Returns count of group members of the unopened notification. This method is designed to cache group by query result to avoid N+1 call. @api protected
@return [Integer] Count of group members of the unopened notification
# File lib/activity_notification/orm/active_record/notification.rb, line 184 def unopened_group_member_count # Cache group by query result to avoid N+1 call unopened_group_member_counts = target.notifications .unopened_index_group_members_only .group(:group_owner_id) .count unopened_group_member_counts[id] || 0 end
Returns count of group member notifiers of the unopened notification not including group owner notifier. This method is designed to cache group by query result to avoid N+1 call. @api protected
@return [Integer] Count of group member notifiers of the unopened notification
# File lib/activity_notification/orm/active_record/notification.rb, line 214 def unopened_group_member_notifier_count # Cache group by query result to avoid N+1 call unopened_group_member_notifier_counts = target.notifications .unopened_index_group_members_only .includes(:group_owner) .where("group_owners_#{self.class.table_name}.notifier_type = #{self.class.table_name}.notifier_type") .where.not("group_owners_#{self.class.table_name}.notifier_id = #{self.class.table_name}.notifier_id") .references(:group_owner) .group(:group_owner_id, :notifier_type) .count("distinct #{self.class.table_name}.notifier_id") unopened_group_member_notifier_counts[[id, notifier_type]] || 0 end