class Notification

Public Instance Methods

cancel() click to toggle source
# File lib/generators/notifykit/templates/app/models/notification.rb, line 34
def cancel
  return true if self.cancelled_at.present?
  self.update_attribute(:cancelled_at, Time.now)
end
cancelled?() click to toggle source
# File lib/generators/notifykit/templates/app/models/notification.rb, line 39
def cancelled?
  self.cancelled_at.present?
end
click() click to toggle source
# File lib/generators/notifykit/templates/app/models/notification.rb, line 14
def click
  return false if self.cancelled?
  self.click_count += 1
  self.clicked_at ||= Time.now
  self.save
end
deliver() click to toggle source
# File lib/generators/notifykit/templates/app/models/notification.rb, line 48
def deliver
  return if self.email_sent_at.present? || !self.deliver_via_email?

  NotificationsMailer.notify(self.id).deliver
end
ignore() click to toggle source
# File lib/generators/notifykit/templates/app/models/notification.rb, line 28
def ignore
  return false if self.cancelled?
  self.ignored_at ||= Time.now
  self.save
end
read() click to toggle source
# File lib/generators/notifykit/templates/app/models/notification.rb, line 21
def read
  return false if self.cancelled?
  self.read_count += 1
  self.read_at ||= Time.now
  self.save
end
to_param() click to toggle source
# File lib/generators/notifykit/templates/app/models/notification.rb, line 54
def to_param
  self.token
end
unsubscribe() click to toggle source
# File lib/generators/notifykit/templates/app/models/notification.rb, line 43
def unsubscribe
  self.unsubscribed_at ||= Time.now
  self.save
end

Protected Instance Methods

set_email() click to toggle source
# File lib/generators/notifykit/templates/app/models/notification.rb, line 60
def set_email
  return if !self.deliver_via_email?

  self.email ||= self.user.try(:email) rescue nil
end
set_token() click to toggle source

The default size is 16 which is 1/64^16, this is protected by a unique index in the database to absolutely prevent collisions

# File lib/generators/notifykit/templates/app/models/notification.rb, line 68
def set_token
  self.token ||= SecureRandom.urlsafe_base64(16)
end