class ActivityNotification::ORM::Dynamoid::Notification

Notification model implementation generated by ActivityNotification.

Public Class Methods

raise_delete_restriction_error(error_text) click to toggle source

Raise ActivityNotification::DeleteRestrictionError for notifications. @param [String] error_text Error text for raised exception @raise [ActivityNotification::DeleteRestrictionError] DeleteRestrictionError from used ORM @return [void]

# File lib/activity_notification/orm/dynamoid/notification.rb, line 161
def self.raise_delete_restriction_error(error_text)
  raise ActivityNotification::DeleteRestrictionError, error_text
end

Public Instance Methods

after_store() click to toggle source

Call after store action with stored notification

# File lib/activity_notification/orm/dynamoid/notification.rb, line 91
def after_store
  if group_owner?
    self.stored_group_notification_count    = group_notification_count
    self.stored_group_member_notifier_count = group_member_notifier_count
    self.stored_group_members               = group_members.as_json
    self.stored_group_members.each do |group_member|
      # Cast Time and DateTime field to String to handle Dynamoid unsupported type error
      group_member.each do |k, v|
        group_member[k] = v.to_s if v.is_a?(Time) || v.is_a?(DateTime)
      end
    end
    save
  else
    group_owner.after_store
  end
end
group_members() click to toggle source

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. @scope instance @return [Dynamoid::Criteria::Chain] Database query of the group member notification instances of this notification has_many :group_members, class_name: “ActivityNotification::Notification”, foreign_key: :group_owner_id

# File lib/activity_notification/orm/dynamoid/notification.rb, line 60
def group_members
  Notification.where(group_owner_id: id)
end
group_owner() click to toggle source

Customized method that belongs to group owner notification instance of this notification. @raise [Errors::RecordNotFound] Record not found error @return [Notification] Group owner notification instance of this notification

# File lib/activity_notification/orm/dynamoid/notification.rb, line 50
def group_owner
  group_owner_id.nil? ? nil : Notification.find(group_owner_id)
end
group_owner?() click to toggle source

Returns if the notification is group owner. Calls NotificationApi#group_owner? as super method. @return [Boolean] If the notification is group owner

# File lib/activity_notification/orm/dynamoid/notification.rb, line 153
def group_owner?
  super
end
prepare_to_store() click to toggle source

Returns prepared notification object to store @return [Object] prepared notification object to store

# File lib/activity_notification/orm/dynamoid/notification.rb, line 79
def prepare_to_store
  self.stored_notifiable_path           = notifiable_path
  self.stored_printable_notifiable_name = printable_notifiable_name
  if group_owner?
    self.stored_group_notification_count    = 0
    self.stored_group_member_notifier_count = 0
    self.stored_group_members               = []
  end
  self
end

Protected Instance Methods

opened_group_member_count(limit = ActivityNotification.config.opened_index_limit) click to toggle source

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 @todo Avoid N+1 call

@param [Integer] limit Limit to query for opened notifications @return [Integer] Count of group members of the opened notification

# File lib/activity_notification/orm/dynamoid/notification.rb, line 184
def opened_group_member_count(limit = ActivityNotification.config.opened_index_limit)
  limit == 0 and return 0
  group_members.opened_only(limit).to_a.length
end
opened_group_member_notifier_count(limit = ActivityNotification.config.opened_index_limit) click to toggle source

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 @todo Avoid N+1 call

@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/dynamoid/notification.rb, line 211
def opened_group_member_notifier_count(limit = ActivityNotification.config.opened_index_limit)
  limit == 0 and return 0
  group_members.opened_only(limit)
               .filtered_by_association_type("notifier", notifier)
               .where("notifier_key.ne": notifier_key)
               .to_a
               .collect {|n| n.notifier_key }.compact.uniq
               .length
end
unopened_group_member_count() click to toggle source

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 @todo Avoid N+1 call

@return [Integer] Count of group members of the unopened notification

# File lib/activity_notification/orm/dynamoid/notification.rb, line 173
def unopened_group_member_count
  group_members.unopened_only.count
end
unopened_group_member_notifier_count() click to toggle source

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 @todo Avoid N+1 call

@return [Integer] Count of group member notifiers of the unopened notification

# File lib/activity_notification/orm/dynamoid/notification.rb, line 195
def unopened_group_member_notifier_count
  group_members.unopened_only
               .filtered_by_association_type("notifier", notifier)
               .where("notifier_key.ne": notifier_key)
               .to_a
               .collect {|n| n.notifier_key }.compact.uniq
               .length
end